Capturing Web Content
WebView
’s CapturePreviewToStreamAsync
method enables you to take a screenshot of its rendered HTML and retrieve it as an IRandomAccessStream
. The following code uses this on a WebView
named webView
then sends the content to an Image
named image
:
async Task ShowContent() { using (InMemoryRandomAccessStream ras = new InMemoryRandomAccessStream()) { await this.webView.CapturePreviewToStreamAsync(ras); WriteableBitmap bitmap = new WriteableBitmap((int)this.webView.ActualWidth, (int)this.webView.ActualHeight); await bitmap.SetSourceAsync(ras); this.image.Source = bitmap; } }
This is different from taking a screenshot with
Get Universal Windows® Apps with XAML and C# Unleashed now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.