tags:

views:

388

answers:

3

How to add images in Silver light?

+3  A: 

If you simply want to add a local image to an xaml control use the following:

<Image x:Name="LocalImage" Source="Path/MyImage.png" Margin="10,10,0,0" Width="16" Height="16" HorizontalAlignment="Left" VerticalAlignment="Top" />

If this is not what you want, then you may need to be more detailed with your question.

Luke Baulch
+1  A: 

The first thing you should do is add the image to your silverlight project. I usually make a folder in my project called images.

Once you have the images in your project then you will ensure that on publish these images will also get published.

The second thing I have learned the hard way is that silverlight does not support all kinds of images. Mainly you can't use jpegs. I suggest you use png file format.

To convert your images to png I use a free imaging application called Paint.net

Once you have a png image in your project then add the image using XAML like this:

<Canvas>
<Image Source="Images/OnlineChess.png" Stretch="Fill" Canvas.Left="350" Canvas.Top="74"
                           Width="100" Height="103" Margin="10,10,10,10"/>
</Canvas>

If this helps please mark the post as answered.

Thank you

Adam Berent

www.adamberent.com

Adam Berent