Xamarin Forms Map Pin渲染器打开页面 [英] Xamarin Forms Map pin renderer open page

查看:104
本文介绍了Xamarin Forms Map Pin渲染器打开页面的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对Xamarin上的Renderers感到陌生.我正在关注本教程( https ://developer.xamarin.com/guides/xamarin-forms/application-fundamentals/custom-renderer/map/customized-pin/)制作自定义图钉.问题如下:

I am prety new with Renderers on Xamarin. I am following this tutorial (https://developer.xamarin.com/guides/xamarin-forms/application-fundamentals/custom-renderer/map/customized-pin/) to make a custom pin. The problem it's the following:

我需要做一个自定义图钉,该自定义图钉只有2个默认标签和1个按钮.该按钮需要打开PCL项目中的页面.我该如何单击按钮转到PCL页面?

I need to do a custom pin, the custom pin only has 2 default labels and 1 Button. That button needs open a page from PCL project. How can I do that click button go to PCL page?

推荐答案

只要单击图钉,您就可以从自定义MapRenderer发送消息.

You can send a message from your custom MapRenderer whenever a pin is clicked using the Xamarin MessagingCenter like so:

Xamarin.Forms.MessagingCenter.Send(YourObject, "PinClicked");

然后在PCL中的某个位置订阅该消息,如下所示:

And then subscribe to that message somewhere in your PCL, like so:

MessagingCenter.Subscribe<string> (this, "PinClicked", (YourObject) => {
            // show the correct page whenever the "PinClicked" message 
            // is sent, using the details in YourObject
        });
    });

当您不再希望接收消息时,别忘了退订.

Don't forget to unsubscribe when you no longer wish to receive messages.

这篇关于Xamarin Forms Map Pin渲染器打开页面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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