如何在WP8 WebBrowser控件加载参数之前显示进度条?

时间:2014-06-23 11:59:39

标签: c# windows-phone-8

我有一个WebBrowser控件,我想在这个控件上显示一些url by参数。在webbrower加载页面之前,我需要显示一些进度条或动画。

请帮帮我,这就是我所拥有的:

 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)
    {    
    }

}

谢谢

2 个答案:

答案 0 :(得分:1)

这可以通过使用LoadCompleted属性来实现。

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;
}

查看this样本。

希望它有所帮助!

答案 1 :(得分:0)

试试这个:

webbrowser.Navigate(new Uri(parameterValue)); 

而不是

webbrowser.Source = uri;

设置进度条的属性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" />