问题
I have the experience of adding the progress bars and progress rings while calling async functions . That has been an easy job as it relies on only IsIndeterminate and IsActive properties of progress bar and progress ring respectively .
Now my question is that , how to show a progress bar/ring in the app while some webpage is loading in the webview control of a windows 8 app .
I am searching for a property or event , that tells the web page in web view is currently in loading state . If somebody came across such a property , please write it up else if you have any other solutions , please do tell it !
回答1:
first declare the delegate
public delegate void LoadCompletedEventHandler( object sender, NavigationEventArgs e);
add the following code logically in an area at which event the progress bar/ring must start showing up.
ProgressRing1.IsActive = true; //for progress ring
ProgressBar1.IsIndeterminate = true; //for progress bar
Add this line to transfer the control to the event which determines whether the webview control has fully loaded the webpage.
WebView1.LoadCompleted += new Windows.UI.Xaml.Navigation.LoadCompletedEventHandler(WebView1_LoadCompleted);
Define the below function to handle what happens when the webpage has been fully loaded ( your aim is to hide the progress bar/ring at this point of time )
void WebView1_LoadCompleted(object sender, Windows.UI.Xaml.Navigation.NavigationEventArgs e)
{
//code for hiding progress bar/ring
ProgressRing1.IsActive = false; //for progress ring
ProgressBar1.IsIndeterminate = false; //for progress bar
}
For further reference you may check out this MSDN page.
回答2:
You should be able turn busy off in DocumentCompleted or Navigated
, with Navigated
I believe you'd have to compare with the original link as it fires on redirects.
回答3:
Just a correction, If you are using it for phone, then instead of
`new Windows.UI.Xaml.Navigation.LoadCompletedEventHandler(WebView1_LoadCompleted);`
the event handler would be
`new System.Windows.Navigation.LoadCompletedEventHandler(WebView1_LoadCompleted);`
来源:https://stackoverflow.com/questions/15536933/show-progress-bar-ring-in-windows-8-app-while-a-webpage-is-loading-in-webview-co