I'll point you to a particularly useful video by Jason Dolinger.
Coming from a WinForms world, implementing any MVX style pattern seemed like more hassle than it was worth but after working with WPF for a couple of years now, I can honestly say that I wouldn't consider anything less. The whole paradigm is supported out-of-the-box.
First off, the key benefit is enabling true separation between the view
and model
. What that means in real terms is that if/when your model needs to change, it can without the view needing to and vice-versa.
Secondly, while your model
may contain all the data you might need in your view
, you may want to abstract that data in such a way that your model
doesn't support. For example, say your model contains a date property. In the model it can exist solely as a DateTime
object but your view might want to present it in a completely different way. Without the viewmodel
you'd either have to duplicate the property in the model
to support the view or modify the property which could seriously obfuscate the 'model'.
You can also use a viewmodel
to aggregate parts of your model that exist in separate classes/libraries to facilitate a more fluent interface for the view
to deal with. It's very unlikely that you'll want to work with data in your code in the same way that a user will want to or will want that data presented to them.
On top of that, you get support for automatic two-way data binding between the view
and viewmodel
.
There really is a whole bunch of extra stuff that I could bang on about but Jason say's it far better that I could so my advice is watch the video. After a few days of working like this, you'll wonder how you ever got by without it.
Good luck.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…