Select to view content in your preferred language

MVVM Samples involving the GeoViewTapped eventre there

01-29-2019 08:25 AM
Occasional Contributor

This question has been asked before, I know, but none of the answers I've seen are straight forward enough for me to follow. Are there any good COMPLETE code samples that demonstrate setting up the GeoViewTapped event using MVVM?


Mike Hamsa

0 Kudos
3 Replies
Esri Notable Contributor

How to respond to view-events in a purist MVVM way depends on the MVVM framework you're using and the platform you're on. I'd suggest you look at how it's done for a click event on a button with the framework you're using, and the approach should be very similar. If you're using UWP, you can even use x:Bind to bind an event straight to a method and forwarding the event arguments to that method. Some MVVM frameworks often provides some sort of attached property that forwards the event to a method.

Having said that, I think the 100% purist MVVM approach is a waste of time, and many of the MVVM framework developers agree that avoiding code-behind for the sake of avoiding code-behind is taking MVVM too far with no real benefit. Code behind is ok, as long as it is view-specific code - so there's not really anything wrong with responding to a click event and forwarding the necessary arguments to your VM (I'd even argue it makes your code flow easier to follow). It's really no different than defining for instance an EventToCommand attached property or similar thing approach in XAML markup, as it's generating the exact same thing, and you still have the important separation of concerns.

Occasional Contributor


Thanks for the response. I'm trying to wire things up using the EventToCommand pattern for Xamarin Forms and it just isn't working. Seems to be fairly straightforward, but I'm not getting it. When wire up the event to command in XAML, my command doesn't get executed - I don't think its actually getting wired up correctly. When I wire up the event to command in code (view page constructor), I'm getting an unhandled exception when it tries to set the EventName on the behavior.

I'll try a few more things and see what I can come up with.

Thanks Again,


0 Kudos
Occasional Contributor

Take a look at the Data Collection Example App. It is a complete application built using MVVM. The Identify operation is performed on GeoviewTapped. Take a look at how it's set up using an Identify Controller to abstract the Identify logic from the view. I'm happy to answer any questions you may have after looking at this app.