BitmapImage.ImageFailed Event
Definition
Important
Some information relates to prerelease product that may be substantially modified before it’s released. Microsoft makes no warranties, express or implied, with respect to the information provided here.
Occurs when there is an error associated with image retrieval or format.
public:
virtual event ExceptionRoutedEventHandler ^ ImageFailed;
// Register
event_token ImageFailed(ExceptionRoutedEventHandler const& handler) const;
// Revoke with event_token
void ImageFailed(event_token const* cookie) const;
// Revoke with event_revoker
BitmapImage::ImageFailed_revoker ImageFailed(auto_revoke_t, ExceptionRoutedEventHandler const& handler) const;
public event ExceptionRoutedEventHandler ImageFailed;
function onImageFailed(eventArgs) { /* Your code */ }
bitmapImage.addEventListener("imagefailed", onImageFailed);
bitmapImage.removeEventListener("imagefailed", onImageFailed);
- or -
bitmapImage.onimagefailed = onImageFailed;
Public Custom Event ImageFailed As ExceptionRoutedEventHandler
<BitmapImage ImageFailed="eventhandler"/>
Event Type
Remarks
One scenario for handling ImageFailed is to set the UriSource to a different local image file that can serve as a fallback value. For example, if you are trying to display an external image where it's possible that the source is no longer there, or for when the user has no Internet connection, you could set the UriSource to reference a local fallback or placeholder image that's part of your app package and is always guaranteed to be available.
private void BitmapImage_ImageFailed(object sender, ExceptionRoutedEventArgs e) {
BitmapImage bitmapImage = sender as BitmapImage;
bitmapImage.UriSource = new Uri("ms-appx:///Images/fallback.png");
}