How to set an image in an Image Control in Windows Phone 7?

Hello everyone……

Windows Phone 7 with it’s simplicity has become really easy to study and code. In today’s tutorial I will show you how to set an image in an image control in windows phone 7.
Assuming you have place the image control in the xaml file. I will first show you how to set the image source in the xaml file.

<image Name=”imgMyImage” Source=”images/coderzheaven.png” />

Assuming that you have placed an imaged named “coderzheaven.png” inside images folder in the solution explorer.

Now if we want to dynamically set the image in code we do this.

myimage.Source = (ImageSource)new ImageSourceConverter().ConvertFromString(“images/coderzheaven.png”);

Since the result from ConvertFromString is an object we have to cast it to an ImageSource.

You can also set it in the properties window of the image. Click on the image control and in the properties window. do this..

Adding image source in windows phone 7

Adding image source in windows phone 7

Please leave your valuable comments on this post.

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>