Question

I'm trying to download an image and set it as the source of a BitmapImage. But there's potentially a case where the image doesn't exist, i.e. the response is a 404. I'm currently doing this:

BitmapImage bitmapImage = new BitmapImage(new Uri("link_to_image"));

Although there are no errors, I prefer to handle the case and show a message or something instead of just showing a blank BitmapImage. Is there a way to get the status code of the response? Or is there a different approach?

Était-ce utile?

La solution

Subscribe to the bitmapImage.DownloadFiled event. Reason for the failure can be read from ExceptionEventArgs in the event handler.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top