Click to See Complete Forum and Search --> : [RESOLVED] Silverlight Image
peteshir
Oct 4th, 2009, 10:47 PM
I have an image in a silverlight project. When I click a button I want the image to change to another image.
I saw that there is an imagesource property but I cannot simply put the Url of the new image in there.
Can someone help
Thanks
Pete
MattP
Oct 7th, 2009, 06:16 PM
Typed this straight in so apologies in advance for syntax errors.
Make sure you've imported System.Windows.Resources and System.Windows.Media.Imaging
If TheImage.png is located in Images folder and build action is set to Resource:
Dim sri As StreamResourceInfo = Application.GetResourceStream(New Uri("SilverlightApplication1;component/Images/TheImage.png", UriKind.Relative))
Dim bmp As New BitmapImage
bmp.SetSource(sri.Stream)
image1.Source = bmp
If TheImage.png is located in Images folder and build action is set to Content:
Dim sri As StreamResourceInfo = Application.GetResourceStream(New Uri("Images/TheImage.png", UriKind.Relative))
Dim bmp As New BitmapImage
bmp.SetSource(sri.Stream)
image1.Source = bmp
If TheImage.png is somewhere out on the web:
image1.Source = New BitmapImage(New Uri("http://domain.com/TheImage.png", UriKind.Absolute))
peteshir
Oct 8th, 2009, 12:03 AM
Thanks. But I am having trouble with bmp.sersource.
BMP does not seem to have that method.
MattP
Oct 8th, 2009, 10:48 AM
It's definitely available in Silverlight 3 when I try it. BitmapImage should be in System.Windows.Media.Imaging.
peteshir
Oct 8th, 2009, 02:53 PM
This is how I got it to work.
Image1.Source = New BitmapImage(New Uri("Photos/BrownBush.jpg", UriKind.RelativeOrAbsolute))
I had trouble with the code you sent Matt. I really don't know why. But this seemed to do the trick. Thanks for you help.
vbforums.com
Copyright Internet.com Inc., All Rights Reserved.