BitmapImage.ImageFailed Event

Definition

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");
}

Applies to

See also