WebViewBrush WebViewBrush WebViewBrush Class

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

Syntax

Declaration

public sealed class WebViewBrushpublic sealed class WebViewBrushPublic NotInheritable Class WebViewBrush
<WebViewBrush .../>

Inheritance Hierarchy

Inherited Members

Inherited properties

, , , , , , , , , , , ,

Inherited methods

, , , , , ,

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(WebView), 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 Fill or 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(WebView) on the WebViewBrush until the source content is fully loaded (for example by calling SetSource(WebView) in the handler for the 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.

<Grid x:Name="Output" Grid.Row="1">
    <Grid.RowDefinitions>
        <RowDefinition Height="Auto"/>
        <RowDefinition Height="*"/>
    </Grid.RowDefinitions>
    <ComboBox x:Name="ComboBox1" Height="50" Width="200" HorizontalAlignment="Left" Margin="10,0,0,0">
        <ComboBoxItem>
            <x:String>First Item</x:String>
        </ComboBoxItem>
        <ComboBoxItem>
            <x:String>Second Item</x:String>
        </ComboBoxItem>
        <ComboBoxItem>
            <x:String>Third Item</x:String>
        </ComboBoxItem>
        <ComboBoxItem>
            <x:String>Fourth Item</x:String>
        </ComboBoxItem>
        <ComboBoxItem>
            <x:String>Fifth Item</x:String>
        </ComboBoxItem>
        <ComboBoxItem>
            <x:String>Sixth Item</x:String>
        </ComboBoxItem>
        <ComboBoxItem>
            <x:String>Seventh Item</x:String>
        </ComboBoxItem>
    </ComboBox>
    <Border BorderThickness="1" BorderBrush="#FF707070"  Grid.Row="1" Margin="10,0,0,0">
        <Grid>
            <WebView x:Name="WebView6" />
            <Rectangle x:Name="Rect1"/>
        </Grid>
    </Border>
</Grid>
void SDKSample::WebViewControl::Scenario6::ComboBox1_DropDownOpened(
    Platform::Object^ sender, Platform::Object^ e)
{
    if (Rect1->Visibility == Windows::UI::Xaml::Visibility::Visible)
    {
        WebViewBrush^ b = ref new WebViewBrush();
        b->SourceName = "WebView6";
        b->Redraw();
        Rect1->Fill = b;
        WebView6->Visibility = Windows::UI::Xaml::Visibility::Collapsed;    
    }
}

void SDKSample::WebViewControl::Scenario6::ComboBox1_DropDownClosed(
    Platform::Object^ sender, Platform::Object^ e)
{
    WebView6->Visibility = Windows::UI::Xaml::Visibility::Visible;
    Rect1->Fill = ref new SolidColorBrush(Windows::UI::Colors::Transparent);
}
void ComboBox1_DropDownOpened(object sender, object e)
{
    if (Rect1.Visibility == Windows.UI.Xaml.Visibility.Visible)
    {
        WebViewBrush b = new WebViewBrush();
        b.SourceName = "WebView6";
        b.Redraw();
        Rect1.Fill = b;
        WebView6.Visibility = Windows.UI.Xaml.Visibility.Collapsed;
    }
}

void ComboBox1_DropDownClosed(object sender, object e)
{
    WebView6.Visibility = Windows.UI.Xaml.Visibility.Visible;
    Rect1.Fill = new SolidColorBrush(Windows.UI.Colors.Transparent);
}
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"
        b.Redraw()
        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

Constructors summary

Initializes a new instance of the WebViewBrush class.

Properties summary

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

Identifies the SourceName dependency property.

Methods summary

Causes the WebViewBrush to get updated source pixels from the associated WebView and its current content. This happens asynchronously.

Sets the source of the content for the WebViewBrush.

Constructors

  • WebViewBrush()
    WebViewBrush()
    WebViewBrush()
    WebViewBrush()

    Initializes a new instance of the WebViewBrush class.

    public WebViewBrush()public New()Public Sub New()public WebViewBrush()

Properties

  • SourceName
    SourceName
    SourceName
    SourceName

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

    public string SourceName { get; set; }public string SourceName { get; set; }Public ReadWrite Property SourceName As stringpublic string SourceName { get; set; }
    <WebViewBrush SourceName="nameOfWebView"/>
    

    Property Value

    Remarks

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

  • SourceNameProperty
    SourceNameProperty
    SourceNameProperty
    SourceNameProperty

    Identifies the SourceName dependency property.

    public static DependencyProperty SourceNameProperty { get; }public static DependencyProperty SourceNameProperty { get; }Public Static ReadOnly Property SourceNameProperty As DependencyPropertypublic static DependencyProperty SourceNameProperty { get; }

    Property Value

Methods

  • Redraw()
    Redraw()
    Redraw()
    Redraw()

    Causes the WebViewBrush to get updated source pixels from the associated WebView and its current content. This happens asynchronously.

    public void Redraw()public void Redraw()Public Function Redraw() As voidpublic void Redraw()

    Remarks

    A WebViewBrush is basically a snapshot of the content being displayed in a WebView. It won't show animations or any dynamic changes to the content. Call Redraw() if the source WebView has changed its content significantly and you want to make a new snapshot to display as the WebViewBrush content.

  • SetSource(WebView)
    SetSource(WebView)
    SetSource(WebView)
    SetSource(WebView)

    Sets the source of the content for the WebViewBrush.

    public void SetSource(WebView source)public void SetSource(WebView source)Public Function SetSource(source As WebView) As voidpublic void SetSource(WebView source)

    Parameters

    Remarks

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

Device family

Windows 10 (introduced v10.0.10240.0)

API contract

Windows.Foundation.UniversalApiContract (introduced v1)

Attributes

Windows.Foundation.Metadata.ActivatableAttribute
Windows.Foundation.Metadata.ContractVersionAttribute
Windows.Foundation.Metadata.MarshalingBehaviorAttribute
Windows.Foundation.Metadata.StaticAttribute
Windows.Foundation.Metadata.ThreadingAttribute
Windows.Foundation.Metadata.WebHostHiddenAttribute

Details

Assembly

Windows.UI.Xaml.Controls.dll