Subscribe to the bitmapImage.DownloadFiled event. Reason for the failure can be read from ExceptionEventArgs in the event handler.
How to handle a BitmapImage when giving a image URI that doesn't exist?
-
07-07-2023 - |
题
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?
解决方案
不隶属于 StackOverflow