我想在下载内容时显示UWP Web View
的进度。这就是我所做的:
main_page.xaml:
<Page
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d" d:DesignWidth="480" d:DesignHeight="768"
FontFamily="{StaticResource PhoneFontFamilyNormal}"
FontSize="20"
Foreground="#FF000000">
<!--LayoutRoot is the root grid where all page content is placed-->
<Grid x:Name="_grid" Background="Transparent">
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Height="*"/>
</Grid.RowDefinitions>
<!--TitlePanel contains the name of the application and page title-->
<!--ContentPanel - place additional content here-->
<Grid x:Name="_contentPanel" Grid.Row="1" Margin="0,0,0,0">
<WebView
x:Name="webView"
Margin="0,0,0,0"
Grid.Row="1"
/>
<ProgressBar x:Name="_progressBar" Margin="10,10,0,754" IsIndeterminate="False" Visibility="Collapsed"/>
</Grid>
</Grid>
在NavigationStarting事件中,我显示了进度条:
private async void WebView_Navigation_Starting(WebView sender, WebViewNavigationStartingEventArgs args)
{
//show progress bar
_progressBar.Visibility = Visibility.Visible;
.......
}
我在加载内容时隐藏它:
void WebView_LoadCompleted(object sender, NavigationEventArgs e)
{
//show progress bar
_progressBar.Visibility = Visibility.Collapsed;
}
这里是我想要更新进度条中进度值的地方。但是如何获取加载的Web视图内容的实际百分比值?
void WebView_Content_Loading(WebView sender, WebViewContentLoadingEventArgs args) {
webView.SetValue(???);
}