Xamarin Forms Map pin renderer open page

浪尽此生 提交于 2019-12-13 09:50:52

问题


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:

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?


回答1:


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");

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.



来源:https://stackoverflow.com/questions/47031955/xamarin-forms-map-pin-renderer-open-page

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!