试试MSDN-Example,它适用于我的项目。如果它不起作用,请创建一个新的干净项目并在没有额外 xaml 的情况下尝试它,也许你会弄乱一些属性;-)
XAML:
<Grid>
<WebView x:Name="contentView" Source="http://www.contoso.com"/>
<Rectangle x:Name="contentViewRect"/>
</Grid>
后面的代码:
private void AppBar_Opened(object sender, object e)
{
WebViewBrush wvb = new WebViewBrush();
wvb.SourceName = "contentView";
wvb.Redraw();
contentViewRect.Fill = wvb;
contentView.Visibility = Windows.UI.Xaml.Visibility.Collapsed;
}
private void AppBar_Closed(object sender, object e)
{
contentView.Visibility = Windows.UI.Xaml.Visibility.Visible;
contentViewRect.Fill = new SolidColorBrush(Windows.UI.Colors.Transparent);
}