【发布时间】:2020-02-07 18:19:40
【问题描述】:
我有一个带有 WebView 的简单 ContentPage。 WebView Source 手动设置为“https://www.turkishairlines.com/”。结果,我看到 Navigating 事件被触发一次,而 Navigated 事件被触发了 3 次。我尝试使用不同的网站并为不同的网站获取不同数量的导航事件。我试图比较触发的导航事件,以找出中间事件和最终事件之间的任何区别,但没有成功。 当网站真正完全加载时,我需要捕捉一个事件。我怎样才能赶上最终的导航事件? MainPage.xaml:
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:d="http://xamarin.com/schemas/2014/forms/design"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d"
x:Class="WebTest.MainPage">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Height="*"/>
</Grid.RowDefinitions>
<Label HorizontalOptions="Center" x:Name="NavCounterLabel"/>
<WebView x:Name="WebV"
HorizontalOptions="FillAndExpand"
VerticalOptions="FillAndExpand"
Grid.Row="1"/>
<ActivityIndicator x:Name="BusyIndicator"
HorizontalOptions="Center"
VerticalOptions="Center"
Color="Red"
HeightRequest="50"
WidthRequest="50"
Grid.Row="1"/>
</Grid>
</ContentPage>
MainPage.xaml.cs:
public partial class MainPage : ContentPage
{
public MainPage()
{
InitializeComponent();
BusyIndicator.IsRunning = BusyIndicator.IsVisible = true;
WebV.Source = "https://www.turkishairlines.com/";
WebV.Navigating += WebV_Navigating;
WebV.Navigated += WebV_Navigated;
}
private void WebV_Navigated(object sender, WebNavigatedEventArgs e)
{
BusyIndicator.IsRunning = BusyIndicator.IsVisible = false;
NavCounterLabel.Text = (Int32.Parse(NavCounterLabel.Text)+1).ToString();
}
private void WebV_Navigating(object sender, WebNavigatingEventArgs e)
{
BusyIndicator.IsRunning = BusyIndicator.IsVisible = true;
NavCounterLabel.Text = "0";
}
【问题讨论】:
标签: xamarin.forms android-webview