WebViewBrush class
Collapse the table of content
Expand the table of content

WebViewBrush class

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




Public NotInheritable Class WebViewBrush
    Inherits TileBrush

<WebViewBrush .../>


The WebViewBrush class has these types of members:


The WebViewBrush class has these constructors.

WebViewBrush Initializes a new instance of the WebViewBrush class.



The WebViewBrush class has these methods. It also inherits methods from the Object class.

ClearValue Clears the local value of a dependency property. (Inherited from DependencyObject)
GetAnimationBaseValue Returns any base value established for a dependency property, which would apply in cases where an animation is not active. (Inherited from DependencyObject)
GetValue Returns the current effective value of a dependency property from a DependencyObject. (Inherited from DependencyObject)
ReadLocalValue Returns the local value of a dependency property, if a local value is set. (Inherited from DependencyObject)
Redraw Causes the WebViewBrush to get updated source pixels from the associated WebView and its current content. This happens asynchronously.
RegisterPropertyChangedCallback Registers a notification function for listening to changes to a specific DependencyProperty on this DependencyObject instance. (Inherited from DependencyObject)
SetSource Sets the source of the content for the WebViewBrush.
SetValue Sets the local value of a dependency property on a DependencyObject. (Inherited from DependencyObject)
UnregisterPropertyChangedCallback Cancels a change notification that was previously registered by calling RegisterPropertyChangedCallback. (Inherited from DependencyObject)



The WebViewBrush class has these properties.

PropertyAccess typeDescription



Gets or sets the horizontal alignment of content in the TileBrush base tile. (Inherited from TileBrush)



Gets or sets the vertical alignment of content in the TileBrush base tile. (Inherited from TileBrush)



Gets the CoreDispatcher that this object is associated with. The CoreDispatcher represents a facility that can access the DependencyObject on the UI thread even if the code is initiated by a non-UI thread. (Inherited from DependencyObject)



Gets or sets the degree of opacity of a Brush. (Inherited from Brush)



Gets or sets the transformation that is applied to the brush using relative coordinates. (Inherited from Brush)



Gets or sets the name of the source WebView control that provides the HTML content.



Identifies the SourceName dependency property.



Gets or sets a value that specifies how the content of this TileBrush stretches to fit its tiles. (Inherited from TileBrush)



Gets or sets the transformation that is applied to the brush. (Inherited from Brush)



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:

  • Reference the source WebView by its identifier name, by setting the SourceName property.
  • Reference the source WebView by reference, by calling the SetSource method and passing a WebView object.
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.

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


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.

<Grid x:Name="Output" Grid.Row="1">
        <RowDefinition Height="Auto"/>
        <RowDefinition Height="*"/>
    <ComboBox x:Name="ComboBox1" Height="50" Width="200" HorizontalAlignment="Left" Margin="10,0,0,0">
            <x:String>First Item</x:String>
            <x:String>Second Item</x:String>
            <x:String>Third Item</x:String>
            <x:String>Fourth Item</x:String>
            <x:String>Fifth Item</x:String>
            <x:String>Sixth Item</x:String>
            <x:String>Seventh Item</x:String>
    <Border BorderThickness="1" BorderBrush="#FF707070"  Grid.Row="1" Margin="10,0,0,0">
            <WebView x:Name="WebView6" />
            <Rectangle x:Name="Rect1"/>

Private Sub ComboBox1_DropDownOpened(sender As Object, e As Object)
    If Rect1.Visibility = Windows.UI.Xaml.Visibility.Visible Then
        Dim b As New WebViewBrush()
        b.SourceName = "WebView6"
        Rect1.Fill = b
        WebView6.Visibility = Windows.UI.Xaml.Visibility.Collapsed
    End If
End Sub

Private Sub ComboBox1_DropDownClosed(sender As Object, e As Object)
    WebView6.Visibility = Windows.UI.Xaml.Visibility.Visible
    Rect1.Fill = New SolidColorBrush(Windows.UI.Colors.Transparent)
End Sub

Requirements (Windows 10 device family)

Device family

Universal, introduced version 10.0.10240.0

API contract

Windows.Foundation.UniversalApiContract, introduced version 1.0


Windows::UI::Xaml::Controls [C++]



Requirements (Windows 8.x and Windows Phone 8.x)

Minimum supported client

Windows 8 [Windows Store apps only]

Minimum supported server

Windows Server 2012 [Windows Store apps only]

Minimum supported phone

None supported


Windows::UI::Xaml::Controls [C++]





See also

Use brushes
XAML WebView control sample



© 2016 Microsoft