CM: advantages not always obvious

Topics: Getting Started
May 2, 2012 at 11:25 AM

Although CM seems to be quite known, as a beginner or potential user of this framework I'm missing sth like a list of good reasons to use CM., e.g. 

"To get the feature XY: This you would have to do without CM:  .......and this is what you just  need to do to achieve this in CM: ............"


When I first came in conatct with CM I thought :"Cool, you just have to provide a method in the viewmodel that is named exactly like a Button and it gets auto-magically fired!"

But regarding property binding between view/ viewmodel:

Using a "conventional" technique (no CM), all you have to do is:

1. Create a viewmodel that implements IPropertyChanged and which is set to the view's datacontext in the ctor of the view (if you want the viewmodels values to be persistent over the whole app lifetime you just have to implement the viewmodel as singelton)

2. in XAML add your prop  <ControlXY  Value={Binding MyValue Mode=TwoWay}/>

3. in the viewmodel: prop MyValue{ get{..}  set{ ...PropChanged(...)}}

When using CM you have additionally to

- create a ModelStorage class

-  add some "Property(x=>x.PropName)...Restore() the ModelStorage for each property to be restored

- maybe spent a lot of time to get your binding convention working for non standard controls


So regarding property synchronsiation between the viewmodel and the view it seems to me that it's more code and classes to create  to achive the same. I don't see the advantages.

Perhaps someone can point me to these (maybe especially in the WP7 context) ?

May 2, 2012 at 12:29 PM

Model storage is not a requirement. It's just an easy way to achieve simple persistence of CM properties across tombstoning. So, the two methods for with vs. without CM are not equivalent. You would have to do a lot more work without CM if you wanted that feature. Also, you don't have to use conventions at all if you don't want to. Just use the features that make the most sense for each scenario. As far as custom controls go, there are some other open source projects that set up the conventions for common control libraries. Personally, I try not to use custom controls, but if I do, I don't usually bother with conventions unless it's a control I am using in a lot of places.

May 2, 2012 at 4:29 PM

Ah, I see, now the advantage is obvious :-)