samira_maleki
samira_maleki

Reputation: 65

web view Xamarin forms

How to use Web View in "Onappering" Event?

protected async override void OnAppearing()
        {
            base.OnAppearing();
            
            if (Settings.Session)
            {
                while (!BrowserMaster.IsInNativeLayout)
                {
                    await Task.Delay(50);

                    CallServer(url);

                }
            }
}

i have a webview in Xamarin forms that used onappering event but error "The full view has not been loaded yet"

Upvotes: 1

Views: 113

Answers (1)

Yaser Moradi
Yaser Moradi

Reputation: 3307

This not only waits for your web view instance to be ready, it also waits for the site to be loaded, so you can use your site's assets.

<?xml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
             xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
             x:Class="App1.TestPage">
    <WebView x:Name="BrowserMaster" Source="https://google.com/" Navigated="BrowserMaster_Navigated" />
</ContentPage>
public partial class TestPage
{
    public TestPage()
    {
        InitializeComponent();
    }

    bool _isFirstTime = true;

    async void BrowserMaster_Navigated(object sender, WebNavigatedEventArgs e)
    {
        if (_isFirstTime)
        {
            _isFirstTime = false;
            await BrowserMaster.EvaluateJavaScriptAsync("alert(document.title)");
        }
    }
}

Upvotes: 1

Related Questions