c# - 无法从自定义渲染器 Xamarin Forms 加载 View

标签 c# xamarin xamarin.forms

我正在使用 xamarin forms 设置跨平台应用程序,我使用本指南使用混合 webview,这样做的目的是使用 openlayers map ,因此,我可以选择标记,并返回这些标记以查看和加载将这些标记列表放入新 View 中。

这是我正在使用的指南

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

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/

相关文章:

c# - 验证 .vhd 文件实际上是 vhd

c# - 如何测量 C# 程序的大小

xamarin - 如何将 StaticResource 的名称绑定(bind)到 ViewModel 属性?

c# - Xamarin Master Detail 句柄泛型

Xamarin Forms 已部署 Textview

c# - datagridview 的数据绑定(bind)问题

c# - 如何在 WPF 应用程序中使用 App.config 文件?

android - Xamarin iOS 和 Android 是如何工作的?

.net - MonoTouch 中的 CLLocationDegrees 在哪里?

xamarin - 在Click事件上分配/返回值,在DependencyService上发送/接收返回值