I have a simple ContentPage with WebView. WebView Source is manually set to "https://www.turkishairlines.com/". As a result, I see that Navigating event is fired once while Navigated event is fired three times. I tried with different web sites and getting different numbers of Navigated events for different sites. I tried to compare fired Navigated events to find any difference between intermediate and final event but with no success. I need to catch an event when a web site is really loaded completely. How can I catch the final Navigated event? 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";
}