"LayoutRoot.Children.Add(image);" at the end of your code, and see what happens~
Silverlight will not render or load your image if this element is not in the visual tree, so add it to your "SomeParent"'s children list, and make it "alive", so you'll catch the MessageBox!
Try it, and if I've missed something pls tell me, nice to work around with this platform~
I believe it's good design. Don't start downloading images until you really need them is how I would want it. You can always remove it again if it fails. There's also precedence for this (HTML).
As you mention you can always use the WebClient object to download it manually, however that requires you to either get it from the host server or have a policy file on the server your are getting the images from. Just remember that downloading it manually
doesn't guarantee that the image loads. Ie. if the file you downloaded is corrupt.
--
/Morten | Silverlight MVP | blog - twitter Please click on "Mark as Answer" if this answered your question.
albertpascual
Member
212 Points
46 Posts
Possible bug on Image events not firing
Apr 23, 2009 01:05 AM | LINK
Guys,
I believe there is a problem in the Image, using the code below none of the events will fire:
BitmapImage bi = new BitmapImage(new Uri("invalidurlpp", UriKind.Absolute)); Image image = new Image(); image.ImageFailed += (object senderFailed, ExceptionRoutedEventArgs eFailed) =>{
MessageBox.Show("Image Failed");};
image.Loaded += (object senderLoaded, RoutedEventArgs eLoaded) =>{
MessageBox.Show("Image Loaded");};
image.Source = bi;
Al
My Blog
struggle-luan
Member
592 Points
104 Posts
Re: Possible bug on Image events not firing
Apr 23, 2009 03:54 AM | LINK
[:D]
Hi~ This is not an error but thank you though~
Try to add
"LayoutRoot.Children.Add(image);" at the end of your code, and see what happens~
Silverlight will not render or load your image if this element is not in the visual tree, so add it to your "SomeParent"'s children list, and make it "alive", so you'll catch the MessageBox!
Try it, and if I've missed something pls tell me, nice to work around with this platform~
albertpascual
Member
212 Points
46 Posts
Re: Possible bug on Image events not firing
Apr 23, 2009 05:33 PM | LINK
So the events happen after you bind it, yet then is too late for me to know if I want to bind a broken image, I believe this is bad design.
I had to write code to download it twice now, one to check if the image exisit using WebClient so I know if I want to bind it!
Thanks man, at least ansewerd my question.
Al
My Blog
SharpGIS
Contributor
4825 Points
832 Posts
Re: Possible bug on Image events not firing
Apr 23, 2009 06:53 PM | LINK
I believe it's good design. Don't start downloading images until you really need them is how I would want it. You can always remove it again if it fails. There's also precedence for this (HTML).
As you mention you can always use the WebClient object to download it manually, however that requires you to either get it from the host server or have a policy file on the server your are getting the images from. Just remember that downloading it manually doesn't guarantee that the image loads. Ie. if the file you downloaded is corrupt.
/Morten | Silverlight MVP | blog - twitter
Please click on "Mark as Answer" if this answered your question.