Dela via


SvgImageSource.OpenFailed Event

Definition

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

// Register
event_token OpenFailed(TypedEventHandler<SvgImageSource, SvgImageSourceFailedEventArgs const&> const& handler) const;

// Revoke with event_token
void OpenFailed(event_token const* cookie) const;

// Revoke with event_revoker
SvgImageSource::OpenFailed_revoker OpenFailed(auto_revoke_t, TypedEventHandler<SvgImageSource, SvgImageSourceFailedEventArgs const&> const& handler) const;
public event TypedEventHandler<SvgImageSource,SvgImageSourceFailedEventArgs> OpenFailed;
function onOpenFailed(eventArgs) { /* Your code */ }
svgImageSource.addEventListener("openfailed", onOpenFailed);
svgImageSource.removeEventListener("openfailed", onOpenFailed);
- or -
svgImageSource.onopenfailed = onOpenFailed;
Public Custom Event OpenFailed As TypedEventHandler(Of SvgImageSource, SvgImageSourceFailedEventArgs) 
<SvgImageSource OpenFailed="eventhandler"/>

Event Type

Remarks

You can use the OpenFailed event to determine why the SVG didn't load correctly by checking the SvgImageSourceFailedEventArgs, which contain error information in the Status property. One scenario for handling OpenFailed is to set the UriSource to a different local SVG source file that can serve as a fallback value. For example, if you are trying to display an external image where it's possible that either the source is no longer there, the user has no Internet connection, or the SVG source is not in the correct format, you could set the UriSource to reference a local fallback or placeholder SVG that's part of your app package and is always guaranteed to be available.

private void SvgImageSource_OpenFailed(SvgImageSource sender, SvgImageSourceFailedEventArgs args) {
    if(args.Status != SvgImageSourceLoadStatus.Success) {
        sender.UriSource = new Uri("ms-appx:///Assets/fallback.svg");
    }
}

Applies to