如何为Windows Mobile app的webview项目添加进度条或进度环

时间:2016-04-29 05:43:41

标签: windows-phone-8 webview windows-phone-8.1 windows-phone

我为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.");
         }
      }
   }
}

1 个答案:

答案 0 :(得分:0)

在您的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;
        }