var image = new BitmapImage();
image.ImageFailed += (s, e) => {
// ...
};
image.UriSource = new Uri("someurl", UriKind.Absolute);
In the documentation it’s mentioned that the ImageFailed event can be raised by:
- File not found.
- Invalid (unrecognized or unsupported) file format.
- Unknown file format decoding error after upload
Is it possible to detect which one of these conditions caused it inside the event?
Yes, since the event argument is a ExceptionRoutedEventArgs which have a ErrorException property, in which you can check for following exception types:
SecurityExceptionFileNotFoundExceptionNotSupportedExceptionCOMExceptionRead the details on MSDN
Example: