SvgImageSource.SetSourceAsync(IRandomAccessStream) Method

Definition

Sets the source SVG for a SvgImageSource by accessing a stream and processing the result asynchronously.

public:
 virtual IAsyncOperation<SvgImageSourceLoadStatus> ^ SetSourceAsync(IRandomAccessStream ^ streamSource) = SetSourceAsync;
/// [Windows.Foundation.Metadata.RemoteAsync]
IAsyncOperation<SvgImageSourceLoadStatus> SetSourceAsync(IRandomAccessStream const& streamSource);
[Windows.Foundation.Metadata.RemoteAsync]
public IAsyncOperation<SvgImageSourceLoadStatus> SetSourceAsync(IRandomAccessStream streamSource);
function setSourceAsync(streamSource)
Public Function SetSourceAsync (streamSource As IRandomAccessStream) As IAsyncOperation(Of SvgImageSourceLoadStatus)

Parameters

streamSource
IRandomAccessStream

The stream source that sets the SVG source value.

Returns

A SvgImageSourceLoadStatus value that indicates whether the operation was successful. If it failed, indicates the reason for the failure.

Attributes

Examples

This example shown here uses a file stream (obtained using a file picker, not shown) to load an image source by calling SetSourceAsync(IRandomAccessStream). The file picker, stream and call to SetSourceAsync(IRandomAccessStream) are all asynchronous.

// Ensure the stream is disposed once the SVG is loaded
using (IRandomAccessStream fileStream = await file.OpenAsync(Windows.Storage.FileAccessMode.Read))
{
    // Set the SVG source to the selected file
    SvgImageSource svgImage = new SvgImageSource();

    await svgImage.SetSourceAsync(fileStream);
    Scenario2Image.Source = svgImage;
}

Remarks

Setting a SVG source by calling the asynchronous SetSourceAsync(IRandomAccessStream) method avoids blocking the UI thread. For more info on how to use async or await, see Call asynchronous APIs in C# or Visual Basic. If the app changes the SVG source again via SetSourceAsync(IRandomAccessStream) or UriSource while a SetSourceAsync(IRandomAccessStream) call is already in progress, the pending SetSourceAsync(IRandomAccessStream) action will throw a TaskCanceledException.

Applies to