Friday, September 7, 2012

How to get the path of an image in Silverlight?

How to get the path of an image in Silverlight?

I have a image found in the storyboard and now i need to find the path of the image. How to get the path from the below found image?

// Code in which i have the image.

   Image imgFound= FindControl<Image>((UIElement)Layout, typeof(Image), strSelectedimg);     string str=imgFound.Source.Tostring(); 

If i give the second line i get the result in the string variable as "System.Windows.Media.Imaging.BitmapImage" but not the path. If i see through the debugging i can get the path in the "Uri" but how to get the "Uri" in codebehind?

Answers & Comments...

Answer: 1

imgFound.Source is of type "System.Windows.Media.Imaging.BitmapImage". In order to access the properties that you see when debugging you need to cast it to a BitmapImage first.

You cast it like any other object,

var bmp = (BitmapImage)imgFound.Source; 

once you have bmp you can access any of it's properties, e.g.

var uri = bmp.UriSource; 
by : Ferminhttp://stackoverflow.com/users/83096




No comments:

Post a Comment

Send us your comment related to the topic mentioned on the blog