我正在使用 xamarin forms 设置跨平台应用程序,我使用本指南使用混合 webview,这样做的目的是使用 openlayers map ,因此,我可以选择标记,并返回这些标记以查看和加载将这些标记列表放入新 View 中。
这是我正在使用的指南
Javascript 函数是将标记信息正确返回给View。
问题出在下面的代码:
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()));
}
我面临的唯一问题是根本没有加载 SelectedLeads()
,它显示错误
"only the original thread that created a view hierarchy can touch its views xamarin forms"
最佳答案
您强制它在 UI 线程上运行:
Device.BeginInvokeOnMainThread(() =>
{
Navigation.PushAsync(new NavigationPage(new SelectedLeads()));
});
关于c# - 无法从自定义渲染器 Xamarin Forms 加载 View ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57524865/