Delen via


LoadedImageSurface.LoadCompleted Event

Definition

Occurs when the image has been downloaded, decoded and loaded to the underlying ICompositionSurface.

// Register
event_token LoadCompleted(TypedEventHandler<LoadedImageSurface, LoadedImageSourceLoadCompletedEventArgs const&> const& handler) const;

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

// Revoke with event_revoker
LoadedImageSurface::LoadCompleted_revoker LoadCompleted(auto_revoke_t, TypedEventHandler<LoadedImageSurface, LoadedImageSourceLoadCompletedEventArgs const&> const& handler) const;
public event TypedEventHandler<LoadedImageSurface,LoadedImageSourceLoadCompletedEventArgs> LoadCompleted;
function onLoadCompleted(eventArgs) { /* Your code */ }
loadedImageSurface.addEventListener("loadcompleted", onLoadCompleted);
loadedImageSurface.removeEventListener("loadcompleted", onLoadCompleted);
- or -
loadedImageSurface.onloadcompleted = onLoadCompleted;
Public Custom Event LoadCompleted As TypedEventHandler(Of LoadedImageSurface, LoadedImageSourceLoadCompletedEventArgs) 
<LoadedImageSurface LoadCompleted="eventhandler"/>

Event Type

Examples

In this example, we set the size of a SpriteVisual to exactly match the decoded size of a successfully loaded LoadedImageSurface.

private Load_Completed(LoadedImageSurface sender, LoadedImageSourceLoadCompletedEventArgs e)
{
    if(e.Status == LoadedImageSourceLoadStatus.Success){
        // imageVisual is a SpriteVisual than has been previously created and whose brush references the LoadedImageSurface
        Size decodedSize = sender.DecodedSize;
        imageVisual.Size = new Vector2((float)decodedSize.Width, (float)decodedSize.Height);

    } else {
        // Handle a load failure
    }
}

Remarks

The LoadedImageSurface instance will not have a loaded image or sizing information, until this event fires. The LoadCompleted event fires regardless of success or failure and the LoadedImageSourceLoadCompletedEventArgs can be used to determine the status.

The LoadCompleted event fires every time that the surface of an instance of LoadedImageSurface gets populated with an image. This includes:

  • The first time that a LoadedImageSurface is initialized
  • The device recovers from a lost state
  • A DPI change causes a different image source to load
  • The app recovers from a low memory state

Common uses of the LoadCompleted event are to put up a temporary image if the image source may take a long time to load or resize a visual exactly to the decoded size of the LoadedImageSurface.

Applies to