BitmapImage.ImageFailed BitmapImage.ImageFailed BitmapImage.ImageFailed BitmapImage.ImageFailed Event

Definition

Occurs when there is an error associated with image retrieval or format.

public : 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
ImageFailed_revoker ImageFailed(auto_revoke_t, ExceptionRoutedEventHandler const& handler) const;
public event ExceptionRoutedEventHandler ImageFailed
Public Event ImageFailed As ExceptionRoutedEventHandler
<BitmapImage ImageFailed="eventhandler"/>

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

See Also