MVVM - View and ViewModel Problems

Discussion created by schinks on Mar 20, 2012
Latest reply on Feb 28, 2014 by brysageek
Hi all,

I am using the MVVM pattern and the WPF API to build a mapping app.  I have a map object defined in a View and my app logic is defined in a ViewModel.  The ViewModel is set as the datacontext of the View.  Everything works great until I try to do something like work with the draw object in the ViewModel.  The draw constructor requires a reference to the map which I cannot access in the ViewModel.  This of course prevents me from defining the draw object in the ViewModel which is needed to respond to events on the draw object.  I could define the draw object in the View but it goes against the MVVM pattern to reference the View from the ViewModel.  So the dilemma is that I have no way of getting a reference to the map or draw object in the ViewModel and thus no way to handle events raised by those objects and no way to access their properties. 

If I were to define the draw object in my view I could setup commanding to handle some of the logic in the ViewModel, but I have requirements that would be difficult to implement with that design.  I would prefer to have the draw object (and other esri related objects) defined in the ViewModel and bound to the View somehow, but finding a good way to accomplish that is elusive.
Since I am using MVVM (fairly strictly) I do not want any (or very limited) amounts of code in the view code-behind.

Can someone offer guidance on best practices for handling this type of scenario?  Is there a way to make this work?