0
votes

I have a Xamarin.Forms page with a map containing numerous pins. I've built a custom iOS renderer to change the image of the displayed pin.

Once I assign the GetViewForAnnotation delegate, my Xamarin.Forms class no longer receives the "Clicked" event. I can access it through the custom renderer, I do believe, but what I want to do when the user taps the title of the pin is push another Xamarin.Forms page to the navigation stack, and I don't know how to give control back to my Xamarin.Forms app from within my Xamarin.iOS app.

I have a feeling I'll need this type of logic in a few other places... where I need to handle a CustomRenderer event but then pass control back to the Xamarin.Forms app for navigation or other purposes.

So I have a couple directions I'd like to go:

1 - More straightforward - get my "Clicked" event to fire in the Xamarin.Forms app when the map's pin is clicked, even though the iOS app is handling the creation of the pin via a CustomRenderer

2 - More advanced and customizable - pass control back to my Xamarin.Forms app (maybe raise an event related to the Renderer level?)

I'd prefer at this time to just get my Clicked event back, but I'm guessing that may not work once I assign the GetViewForAnnotation event in the CustomRenderer.

1

1 Answers

0
votes

From what I read, you can detect the annotation click within your renderer.

Within your renderer in the OnElementChanged you can get access to the View in the Xamarin.Forms PCL it relates to.

A few possibilities to consider going forward:-

  • a) Use MessagingCenter to convey messaging between interests (see here).

  • b) Use the standard event raising, i.e. public event EventHandler<someEventArgs> OnSomeEvent through your View in your PCL.

  • c) Use an ICommand approach on your View in your PCL if your more MVVM orientated, and invoke this way instead.

Once you have your notification back through your View / Page, depending on where your doing things, you can then do a normal navigation based on the information you have been given from your platform-specific renderer in the PCL.