SvgImageSource.SetSourceAsync(IRandomAccessStream) Method


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

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



The stream source that sets the SVG source value.


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



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;


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