Search code examples
xamarinxamarin.iosxamarin.formsxamarin.androidrenderer

Xamarin Forms Map pin renderer open page


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?


Solution

  • 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.