单击标记时从CustomMapRenderer调用Naviation.PushAsync [英] Calling Naviation.PushAsync from CustomMapRenderer when clicked on a marker

查看:98
本文介绍了单击标记时从CustomMapRenderer调用Naviation.PushAsync的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在将ios aswel作为Android的xamarin项目进行开发,我们在Xamarin.Forms地图上显示自定义标记,我们希望用户单击自定义标记时导航到另一个视图。

I am working on a xamarin project for ios aswel as android where we are showing custom markers on the Xamarin.Forms maps, we want the user to navigate to another view when he clicks on a custom marker.

我们正在使用Navigation.PushAsync在视图中导航。这是通过非平台特定代码和导航的viewmodels完成的。PushAsync只能在此处使用,而不能从平台特定代码使用。 Wich是customMapRenderers所在的位置,并且是单击标记的onlclick所在的位置。

We are using Navigation.PushAsync to navigate through the views. this is done from the viewmodels from the non platform specific code, and navigation.PushAsync can only be used there and not from the platformspecific code. Wich is where the customMapRenderers are and where the onlclick for the markers is handled.

所以我的问题是如何从这些onClick事件导航到另一个视图。下面的
是捕获onclick的方法。

So my question is how can i navigate to another view from these onClick Events. underneath are the methods that catch the onclick.

Android:

private void OnMarkerClick(object sender, GoogleMap.MarkerClickEventArgs e)
        {
            Toast.MakeText(MainApplication.Context, "Button Pressed", ToastLength.Long).Show();
        }

iOS:

private void OnDidSelectAnnotationView(object sender, MKAnnotationViewEventArgs e)
    {
        UIAlertView alert = new UIAlertView()
        {
            Title = "Event",
            Message = "Button Clicked"
        };
        alert.AddButton("Oke");
        alert.Show();
    }


推荐答案

正如Yuri所说,您可以通过使用 Messenger 来实现示例关于如何使用 Messenger 。您可以在自定义渲染器 onClick事件中使用它,当在渲染器中发送消息页面会收到消息。因此,您可以在页面的 MessagingCenter.Subscribe 方法中导航到另一个视图。

As Yuri said, you can implement this by using Messenger, here is a sample about how to use Messenger. You can use it in custom renderer onClick Events, When send a message in renderer, the Page will received Message. So you can navigate to another view in your Page's MessagingCenter.Subscribe method.

页面:

MessagingCenter.Subscribe<MainPage>(this, "Navigation", async (sender) =>
{
     var page1 = new Page1();
     await Navigation.PushModalAsync(page1);
});

自定义渲染器:

MessagingCenter.Send<MainPage>(MainPage.getInstance(), "Navigation");

这篇关于单击标记时从CustomMapRenderer调用Naviation.PushAsync的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆