0
votes

I have implemented the HybridWebView here.

I want to detect when the page has finished loading, but the navigated event does not seem to fire.

<?xml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
             xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
             xmlns:lib="clr-namespace:Xam.Forms.MyStuff"
             x:Class="Xam.Forms.MyStuff.HybridWebView">
    <ContentPage.Content>
        <lib:HybridWebView x:Name="hybridWebView" Uri="index.html"
                Navigated="HybridWebView_Navigated"
                HorizontalOptions="FillAndExpand" VerticalOptions="FillAndExpand"/>
    </ContentPage.Content>
</ContentPage>

Why does the Navigated event not fire? Is it because the source content is loaded locally rather than using an actual URL? If so, is there some other way of detecting when the locally sourced html file has finished loading?

I would even be okay with a way of detecting it inside the individual renderers.

1

1 Answers

0
votes

Create the element and capture the event in the platform-specific renderer. The following example is for UWP, but the pattern applies to iOS and Android as well.

In the OnElementChanged event, create the native WebView element and assign the event handler:

if(Control == null)
{
    var webView = new Windows.UI.Xaml.Controls.WebView();
    {
        webView.Navigate(uri);
    };
    webView.NavigationStarting += WebView_NavigationStarting;
}

Create the event handler:

private void WebView_NavigationStarting(Windows.UI.Xaml.Controls.WebView sender, Windows.UI.Xaml.Controls.WebViewNavigationStartingEventArgs args) {}