简体   繁体   中英

How to show progressbar until WP8 WebBrowser control loaded parameter?

I have a WebBrowser control and I want to show some url by parameter 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:

 public partial class brw : PhoneApplicationPage
{
    public brw()
    {
        InitializeComponent();  
    }

    protected override void OnNavigatedTo(System.Windows.Navigation.NavigationEventArgs e)
    {
        base.OnNavigatedTo(e);
        string parameterValue = NavigationContext.QueryString["parameter"];
        System.Uri uri = new System.Uri(parameterValue);
        webbrowser.Source = uri;

    }


    private void WebBrowser_Navigating_1(object sender, Microsoft.Phone.Controls.NavigatingEventArgs e)
    {
        progressbar.Visibility = Visibility.Visible;
    }

    private void WebBrowser_Navigated_1(object sender, System.Windows.Navigation.NavigationEventArgs e)
    {
        progressbar.Visibility = Visibility.Collapsed;
    }

    private void PhoneApplicationPage_Loaded_1(object sender, System.Windows.RoutedEventArgs e)
    {    
    }

}

Thank you

This can be achieved by using LoadCompleted property.

XAML:

<ProgressBar x:Name="progressbar" IsIndeterminate="True"/>
<phone:WebBrowser x:Name="webbrw" IsScriptEnabled="True" LoadCompleted="yesLoaded"/>

.cs:

private void yesLoaded(object sender, NavigationEventArgs e)
{
    this.progressbar.Visibility = Visibility.Collapsed; 
    this.progressbar.IsIndeterminate = False;
}

Have a look at this sample.

Hope it helps!

try this:

webbrowser.Navigate(new Uri(parameterValue)); 

instead of

webbrowser.Source = uri;

set Progressbar's Property IsIndeterminate="True"

<ProgressBar Foreground="Orange" x:Name="progressbar" Visibility="Collapsed" IsIndeterminate="True" Height="4" HorizontalAlignment="Left" Margin="10,66,0,0" VerticalAlignment="Top" Width="460" />

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM