SvgImageSource.SetSourceAsync(IRandomAccessStream) Metodo

Definizione

Imposta l'oggetto SVG di origine per svgImageSource accedendo a un flusso ed elaborando il risultato in modo asincrono.

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)

Parametri

streamSource
IRandomAccessStream

Origine di flusso che imposta il valore di origine SVG.

Restituisce

Valore SvgImageSourceLoadStatus che indica se l'operazione ha avuto esito positivo. Se non è riuscita, indica il motivo dell'errore.

Attributi

Esempio

In questo esempio viene usato un flusso di file (ottenuto usando una selezione file, non visualizzato) per caricare un'origine immagine chiamando SetSourceAsync(IRandomAccessStream). La selezione file, il flusso e la chiamata a SetSourceAsync(IRandomAccessStream) sono tutti asincroni.

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

Commenti

L'impostazione di un'origine SVG chiamando il metodo SetSourceAsync(IRandomAccessStream) evita di bloccare il thread dell'interfaccia utente. Per altre informazioni su come usare async o await, vedere Chiamare API asincrone in C# o Visual Basic. Se l'app modifica nuovamente l'origine SVG tramite SetSourceAsync(IRandomAccessStream) o UriSource mentre una chiamata SetSourceAsync(IRandomAccessStream) è già in corso, l'azione SetSourceAsync(IRandomAccessStream) genererà un'azione TaskCanceledException.

Si applica a