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?

有帮助吗?

解决方案

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

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top