Condividi tramite


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 del flusso che imposta il valore di origine SVG.

Restituisce

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

Attributi

Esempio

Questo esempio illustrato qui usa 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) asincrono evita di bloccare il thread dell'interfaccia utente. Per altre informazioni su come usare async o await, vedi Chiamare API asincrone in C# o Visual Basic. Se l'app modifica nuovamente l'origine SVG tramite SetSourceAsync(IRandomAccessStream) o UriSource mentre è già in corso una chiamata SetSourceAsync(IRandomAccessStream), l'azione SetSourceAsync(IRandomAccessStream) in sospeso genererà un'eccezione TaskCanceledException.

Si applica a