如何为 windows 移动应用的 webview 项目添加进度条或进度环
How to add progress bar or progress ring for webview project for windows mobile app
我已经为 windows phone 应用程序创建了一个 Webview 项目来加载 google.com。它工作正常,但我无法添加进度条或进度环。谁能帮帮我?
namespace App2
{
public sealed partial class MainPage : Page
{
private static readonly Uri HomeUri = new Uri("http://www.google.com", UriKind.Absolute);
public MainPage()
{
this.InitializeComponent();
this.NavigationCacheMode = NavigationCacheMode.Required;
}
protected override void OnNavigatedTo(NavigationEventArgs e)
{
WebViewControl.Navigate(HomeUri);
HardwareButtons.BackPressed += this.MainPage_BackPressed;
}
protected override void OnNavigatedFrom(NavigationEventArgs e)
{
HardwareButtons.BackPressed -= this.MainPage_BackPressed;
}
private void MainPage_BackPressed(object sender, BackPressedEventArgs e)
{
if (WebViewControl.CanGoBack)
{
WebViewControl.GoBack();
e.Handled = true;
}
}
private void Browser_NavigationCompleted(WebView sender, WebViewNavigationCompletedEventArgs args)
{
if (!args.IsSuccess)
{
Debug.WriteLine("Navigation to this page failed, check your internet connection.");
}
}
}
}
在您的 XAML 中,在 webview 上添加一个进度环,例如使其与 webview 重叠
<Grid>
<Grid x:Name="webViewHolder" >
<WebView x:Name="wvPage" Loaded="WebView_Loaded" NavigationCompleted="WebView_NavigationCompleted" NavigationStarting="wvPage_NavigationStarting"></WebView>
</Grid>
<ProgressRing x:Name="myProgressRing" IsActive="True" Height="90" Width="90" Background="Transparent" Foreground="#EF4D17"/>
</Grid>
现在在代码后面
private void wvPage_NavigationStarting(Windows.UI.Xaml.Controls.WebView sender, WebViewNavigationStartingEventArgs args)
{
myProgressRing.IsActive = true;
}
.
.
.
private void WebView_NavigationCompleted(Windows.UI.Xaml.Controls.WebView sender, WebViewNavigationCompletedEventArgs args)
{
myProgressRing.IsActive = false;
}
我已经为 windows phone 应用程序创建了一个 Webview 项目来加载 google.com。它工作正常,但我无法添加进度条或进度环。谁能帮帮我?
namespace App2
{
public sealed partial class MainPage : Page
{
private static readonly Uri HomeUri = new Uri("http://www.google.com", UriKind.Absolute);
public MainPage()
{
this.InitializeComponent();
this.NavigationCacheMode = NavigationCacheMode.Required;
}
protected override void OnNavigatedTo(NavigationEventArgs e)
{
WebViewControl.Navigate(HomeUri);
HardwareButtons.BackPressed += this.MainPage_BackPressed;
}
protected override void OnNavigatedFrom(NavigationEventArgs e)
{
HardwareButtons.BackPressed -= this.MainPage_BackPressed;
}
private void MainPage_BackPressed(object sender, BackPressedEventArgs e)
{
if (WebViewControl.CanGoBack)
{
WebViewControl.GoBack();
e.Handled = true;
}
}
private void Browser_NavigationCompleted(WebView sender, WebViewNavigationCompletedEventArgs args)
{
if (!args.IsSuccess)
{
Debug.WriteLine("Navigation to this page failed, check your internet connection.");
}
}
}
}
在您的 XAML 中,在 webview 上添加一个进度环,例如使其与 webview 重叠
<Grid>
<Grid x:Name="webViewHolder" >
<WebView x:Name="wvPage" Loaded="WebView_Loaded" NavigationCompleted="WebView_NavigationCompleted" NavigationStarting="wvPage_NavigationStarting"></WebView>
</Grid>
<ProgressRing x:Name="myProgressRing" IsActive="True" Height="90" Width="90" Background="Transparent" Foreground="#EF4D17"/>
</Grid>
现在在代码后面
private void wvPage_NavigationStarting(Windows.UI.Xaml.Controls.WebView sender, WebViewNavigationStartingEventArgs args)
{
myProgressRing.IsActive = true;
}
.
.
.
private void WebView_NavigationCompleted(Windows.UI.Xaml.Controls.WebView sender, WebViewNavigationCompletedEventArgs args)
{
myProgressRing.IsActive = false;
}