我的应用程序是一个Web浏览器。我在XAML中添加了一个进度条,但是当浏览器运行时,进度条不会运行,甚至会出现在GUI上,
我的代码:
protected override void OnNavigatedTo(System.Windows.Navigation.NavigationEventArgs e)
{
webBrowser1.Navigated += new EventHandler<System.Windows.Navigation.NavigationEventArgs>(Browser_Navigated);
webBrowser1.Navigating += new EventHandler<NavigatingEventArgs>(Browser_Navigating);
webBrowser1.Navigate(new Uri("http://nhomxe.vn", UriKind.Absolute));
}
进度:
void Browser_Navigating(object sender, NavigatingEventArgs e)
{
ProgBar.Visibility = Visibility.Visible;
}
void Browser_Navigated(object sender, System.Windows.Navigation.NavigationEventArgs e)
{
ProgBar.Visibility = Visibility.Collapsed;
}
的Xaml:
<!--ContentPanel - place additional content here-->
<Grid x:Name="ContentPanel" Grid.Row="1" Margin="12,0,12,0">
<ProgressBar Foreground="Green" x:Name="ProgBar" Visibility="Collapsed" IsIndeterminate="True" Height="50" HorizontalAlignment="Left" Margin="10,66,0,0" VerticalAlignment="Center" Width="480" />
<phone:WebBrowser Name="webBrowser1" HorizontalAlignment="Stretch" Margin="0,-12,-13,0" VerticalAlignment="Stretch" IsScriptEnabled="True"/>
<phone:WebBrowser Name="webBrowser2" Width="1" Height="1" IsScriptEnabled="True"></phone:WebBrowser>
</Grid>
答案 0 :(得分:0)
试试这个。您可以使用SystemTry
中的ProgressIndicator
protected override void OnNavigatedTo(NavigationEventArgs e)
{
base.OnNavigatedTo(e);
SystemTray.ProgressIndicator = new ProgressIndicator(); // << NEW
webBrowser1.Navigated += new EventHandler<System.Windows.Navigation.NavigationEventArgs>(Browser_Navigated);
webBrowser1.Navigating += new EventHandler<NavigatingEventArgs>(Browser_Navigating);
webBrowser1.Navigate(new Uri("http://nhomxe.vn", UriKind.Absolute));
}
创建以下方法以显示ProgressIndicator
private void DisplayProgressIndicator(bool isvisible, string message = "")
{
SystemTray.ProgressIndicator.Text = message;
SystemTray.ProgressIndicator.IsIndeterminate = isvisible;
SystemTray.ProgressIndicator.IsVisible = isvisible;
}
修改你的事件处理程序。
private void Browser_Navigating(object sender, NavigatingEventArgs e)
{
DisplayProgressIndicator(true, "Loading...");
}
private void Browser_Navigated(object sender, NavigationEventArgs e)
{
DisplayProgressIndicator(false);
}
这应显示SystemTry
答案 1 :(得分:0)
使用此Xaml代码而不是Xaml代码。
<phone:WebBrowser Name="webBrowser1" HorizontalAlignment="Stretch" Margin="0,-12,-13,0" VerticalAlignment="Stretch" IsScriptEnabled="True"/>
<phone:WebBrowser Name="webBrowser2" Width="1" Height="1" IsScriptEnabled="True"></phone:WebBrowser>
<ProgressBar Foreground="Green" x:Name="ProgBar" Visibility="Collapsed" IsIndeterminate="True" Height="50" HorizontalAlignment="Left" Margin="10,66,0,0" VerticalAlignment="Center" Width="480" />
</Grid>