2
votes

I am setting up cross platform app using xamarin forms, I have used this guide to use a hybrid webview, the purpose of this is to use openlayers maps, so, I can select markers, and return those markers to view and load list of those markers into a new view.

This is the guide I am using

https://docs.microsoft.com/en-us/xamarin/xamarin-forms/app-fundamentals/custom-renderer/hybridwebview

Javascript function is return markers information correctly to View.

The problem is code below:

hybridWebView.RegisterAction (data => DisplayAlert ("Alert", "Hello " + data, "OK"));

//I have changed this into this method, and created new function LoadSelectedLeads

hybridWebView.RegisterAction(data => LoadSelectedLeads(data));

// I have used this await or without await too, both didn't work

public async void LoadSelectedLeads(String data)
{
 await Navigation.PushAsync(new NavigationPage(new SelectedLeads()));
}

The only issue I am facing its not loading the SelectedLeads() at all, it shows error this

"only the original thread that created a view hierarchy can touch its views xamarin forms"

2

2 Answers

0
votes

You force it to run it on UI Thread:

  Device.BeginInvokeOnMainThread(() =>
    {
        Navigation.PushAsync(new NavigationPage(new SelectedLeads()));
    });
0
votes

I copied this out of some production code that I have, await ((StartPage)Current.MainPage).Detail.Navigation.PushAsync(page); another way to say this would be await YourNavigationPage.Navigation.PushAsync(new SelectedLeads()); Try this along with and in addition to what Burno shows above.