I have a WebBrowser control and I want to show some url on this control. Until the webbrower loaded the page, I need to show some progressbar or animation.
Please help me, here's what I have:
XAML:
<!--LayoutRoot is the root grid where all page content is placed-->
<Grid x:Name="LayoutRoot" Background="Transparent">
<ProgressBar x:Name="progressbar" IsIndeterminate="True"/>
<phone:WebBrowser x:Name="webbrw" IsScriptEnabled="True"/>
</Grid>
strong text
public MainPage()
{
InitializeComponent();
// Sample code to localize the ApplicationBar
//BuildLocalizedApplicationBar();
Loaded += MainPage_Loaded;
}
void MainPage_Loaded(object sender, RoutedEventArgs e)
{
webbrw.LoadCompleted += webbrw_LoadCompleted;
webbrw.Source = new Uri("http://www.youtube.com/user/tseries");
}
void webbrw_LoadCompleted(object sender, NavigationEventArgs e)
{
progressbar.IsIndeterminate = false;
}
If you simply want to show the bar while loading the page and hide it afterwards, you're using the wrong property. The IsIndeterminate
property reports a generic process (true) or one based on a value (false). To hide the progressbar you should use:
progressbar.Visibility = Visibility.Collapsed;
This can be achieved by using LoadCompleted
property. Hope this solves your problem.
XAML Should be like:
<ProgressBar x:Name="progressbar" IsIndeterminate="True"/>
<phone:WebBrowser x:Name="webbrw" IsScriptEnabled="True" LoadCompleted="yesLoaded"/>
C# for this;
private void yesLoaded(object sender, NavigationEventArgs e)
{
this.progressbar.Visibility = Visibility.Collapsed;
this.progressbar.IsIndeterminate = False;
}
Try using the Navigate method and catch Navigated event instead which triggers after the control navigates successfully. Check the MSDN reference http://msdn.microsoft.com/en-us/library/windowsphone/develop/microsoft.phone.controls.webbrowser_events(v=vs.105).aspx
To handle every possible case, i had to register to these two WebBrowser events LoadCompleted and NavigationFailed.
And of course, suspending the progress in each callback/handler with :
progressbar.IsIndeterminate = false;
I used OnNavigatedTo method to initialize the progressbar as shown below:
protected override void OnNavigatedTo(NavigationEventArgs e)
{
progressbar.IsIndeterminate = true;
//u can add other codes you need
}
then check if the browser is fully loaded using LoadCompleted method as shown below:
private void Browser_LoadCompleted(object sender, NavigationEventArgs e)
{
progressbar.IsIndeterminate = false;
}
notice that the progressbar is a Name I gave to the ProgressBar on xaml and