-api-id | -api-type |
---|---|
M:Windows.UI.Xaml.Media.Imaging.SvgImageSource.SetSourceAsync(Windows.Storage.Streams.IRandomAccessStream) |
winrt method |
Sets the source SVG for a SvgImageSource by accessing a stream and processing the result asynchronously.
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.
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.
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;
}