How to Add an Image to a Silverlight Button

Save

Silverlight is a type of programming language similar to the Macromedia Flash website design language. The Silverlight language is used to create animated websites and extended interactivity for users. One typical task when creating forms in any language is button creation. A button can have a typical layout, but creating buttons with images customizes the form to match the website color scheme. You can create a button with an image by adding an additional image tag in the button's definition.

  • Open the Silverlight editor and double click the form you want to edit in the "Solution Explorer" workspace. Scroll down to the area of the code file where you want to place the button.

  • Create a button using the Silverlight tag. The following code creates a button in Silverlight:
    <Button x:Name="btnTest" Canvas.Top="60" Canvas.Left="30" Click="btnTest_Click" Content="Click me!"></Button>
    The "Canvas" property is in pixels, and it directs where Silverlight places the button. The "click" property is the function called when someone clicks the button. Finally, the "Content" property is the text seen in the button. This text is hidden when you use an image.

  • Use an image for the button. Placing an image tag inbetween the button tags replaces the typical button layout with the image. The following code adds an image to the button:
    <Button x:Name="btnTest" Canvas.Top="60" Canvas.Left="30" Click="btnTest_Click" Content="Click me!">
    <Image x:Name="buttonImage" Source="/Images/myButtonImage.jpg" Width="45" Height="45" />
    </Button>
    Replace "myButtonImage.jpg" with the name of your button image.

References

  • Photo Credit internet image by Soja Andrzej from Fotolia.com
Promoted By Zergnet

Comments

You May Also Like

  • How to Copy to a Clipboard in Silverlight

    Silverlight is a Microsoft Office software program that allows you to develop different media applications for websites, mobile devices and computer desktops....

Related Searches

Check It Out

Geek Vs Geek: Robot battles, hoverboard drag race, and more

M
Is DIY in your DNA? Become part of our maker community.
Submit Your Work!