Skip to content

Latest commit

 

History

History
55 lines (33 loc) · 4.47 KB

webviewbrush.md

File metadata and controls

55 lines (33 loc) · 4.47 KB
-api-id -api-type
T:Windows.UI.Xaml.Controls.WebViewBrush
winrt class

Windows.UI.Xaml.Controls.WebViewBrush

-description

Provides a brush that renders the content that is currently hosted in a WebView control.

-xaml-syntax

<WebViewBrush .../>

-remarks

In Windows 8, the WebView control has the characteristic that other UI regions such as controls cannot be rendered on top of it. This is because of how window regions are handled internally, particularly how input events are processed and how the screen draws. If you want to render HTML content and also place other UI elements on top of that HTML content, you should use WebViewBrush as the render area. The WebView still provides the HTML source information, and you reference that WebView through the SourceName property (or by calling SetSource, the method and property yield the same results). WebViewBrush does not have this overlay limitation, but it doesn't enable interaction.

Note

The preceding remarks apply only to apps compiled for Windows 8, even when running on Windows 8.1. Windows 8.1 introduces changes to the WebView control that fix the issues described here. For Windows 8.1, it's anticipated that scenarios where you'll still use a WebViewBrush won't be very common. In most cases you can just use a WebView control and get the functionality you need.

You can apply a WebViewBrush to any property that takes a Brush. For example, you can set Shape.Fill or Control.Background with a WebViewBrush.

There are two alternatives for associating a WebViewBrush with a WebView control source:

Important

It's often necessary to call Redraw for a WebViewBrush that's declared in XAML in the same UI as is the WebView source. A WebView control has an inherently asynchronous behavior that redraws the control when its content is completely loaded. But an associated WebViewBrush renders as soon as the XAML is parsed (which might be before the URI content is loaded by the WebView). Alternatively, you can wait to call SetSource on the WebViewBrush until the source content is fully loaded (for example by calling SetSource in the handler for the WebView.LoadCompleted event.

This class is not supported on Windows Phone 8.x. WebView content will not be captured.

-examples

The following Windows 8-specific code example demonstrates how to use a WebViewBrush to enable XAML-based content to overlap HTML-based content. In this example, the WebView control is displayed by default so that it remains interactive. When the ComboBox drop-down list is open, however, it overlaps the WebView control. In this case, the WebView is hidden and the WebViewBrush displays the HTML content on a Rectangle occupying the same space.

[!code-xamlWebViewBrushXaml]

[!code-cppWebViewBrushCode]

[!code-csharpWebViewBrushCode]

[!code-vbWebViewBrushCode]

-see-also

TileBrush, Brush, WebView, Use brushes, XAML WebView control sample