AnsweredAssumed Answered

Why not put MapView into a ViewModel and bind it to a ContentControl? (MVVM)

Question asked by klathan on Jul 24, 2015
Latest reply on Mar 21, 2016 by MCederholm

Hi all,

 

I've been working on understanding the new .NET api and how it works with MVVM. (I previously worked with the WPF api and my team used MVVM with no problems.) I'm trying to understand why the MapView was split from the Map and how I should route events to the ViewModel. So far I have 3 approaches I've been looking at:

 

1. Do all event handling in code behind. (Ugg.) Use an event messenger to communicate with the ViewModel if it can't be avoided.

2. Use a Map Controller pattern, as outlined in this post: [blogpost] Navigating the MapView from a ViewModel Do all work in the ViewModel, no code behind.

3. Create my Map and MapView in the ViewModel, bind a ContentControl in the View to display the MapView. Do all work in the ViewModel, no code behind.

 

I am leaning towards #3... it worked for my team in the WPF runtime when we just had a single Map control. #2 seems like a lot of code for what it does. Does anyone know if there are any problems with the third approach? I know it's a little fishy to instantiate a UI element in a ViewModel, but I feel like that is less fishy than creating an elaborate dependency property Map Controller.

 

Thanks!

Outcomes