Skip to content

Latest commit

 

History

History
43 lines (31 loc) · 2.07 KB

svgimagesource_setsourceasync_1118221574.md

File metadata and controls

43 lines (31 loc) · 2.07 KB
-api-id -api-type
M:Microsoft.UI.Xaml.Media.Imaging.SvgImageSource.SetSourceAsync(Windows.Storage.Streams.IRandomAccessStream)
winrt method

Microsoft.UI.Xaml.Media.Imaging.SvgImageSource.SetSourceAsync

-description

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

-parameters

-param streamSource

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.

-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.

-see-also

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