Multiple Views, One VM, WP7

Topics: Conventions, UI Architecture
Nov 11, 2011 at 6:22 PM

So I'm new at WP7 development but getting to be an old hat at Silverlight with CM for MVVM. One thing that I'm bit perplexed with is how to mimic the "One VM multiple Views" scenario in the context of page navigation. I find it so slick that in regular Silverlight I can have one folder under Views named after the base name of the VM, and through context in the xam,l load the appropriate View from said folder. It's clean, it's simple and you only have one VM to contend with.

But with my first WP7 app I'm lost as to how to do this. Page Navigation (URI's for tiles, URI's with the navigation service) forces me into having, say, a DetailItemViewModel, EditItemViewModel, etc, that are all really just a VM for an single entity named Item. I end up replicating the same properties across many classes (VM's and Models). Really am I missing something here? In the context of my app you could structure DetailItemViewl the old Model-First way, but since EditItemView gets navigated to I have no context to pass to the ViewModelLocator.

Should our app view structure look like:





Instead of:




Jan 5, 2012 at 6:37 AM

How about just putting all your logic into EditItemViewModel, and then just create DetailItemViewModel as a subclass with a default constructor and no other override code?

Jan 5, 2012 at 2:29 PM

That was basically what I did. ItemViewModelBase with the properties that I was concerned with duplicating then subclasses of EditItemViewModel and DetailItemViewModel respectively.

I was too hung up on trying to get conventions to work...