SvgImageSource.SetSourceAsync(IRandomAccessStream) 方法

定义

通过访问流并异步处理结果来设置 SvgImageSource 的源 SVG。

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)

参数

streamSource
IRandomAccessStream

设置 SVG 源值的流源。

返回

一个 SvgImageSourceLoadStatus 值,该值指示操作是否成功。 如果失败,则指示失败的原因。

属性

示例

此处所示的此示例使用 (使用文件选取器获取的文件流,而不是显示) 通过调用 SetSourceAsync (IRandomAccessStream) 来加载图像源。 文件选取器、流式传输和调用 SetSourceAsync (IRandomAccessStream) 都是异步的。

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

注解

通过调用异步 SetSourceAsync (IRandomAccessStream) 方法设置 SVG 源可避免阻止 UI 线程。 有关如何使用 asyncawait 的详细信息,请参阅 调用 C# 或 Visual Basic 中的异步 API。 如果在 SetSourceAsync (IRandomAccessStream) 调用正在进行时,应用再次通过 SetSourceAsync (IRandomAccessStream) 或 UriSource 更改 SVG 源,则挂起的 SetSourceAsync (IRandomAccessStream) 操作将引发 TaskCanceledException

适用于