Reputation: 6790
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?
Upvotes: 1
Views: 166
Reputation: 549
Subscribe to the bitmapImage.DownloadFiled event. Reason for the failure can be read from ExceptionEventArgs in the event handler.
Upvotes: 2