Friday, 6 September 2013

MVVM what constitutes a viewmodel?

MVVM what constitutes a viewmodel?

I'm still not totally sure what constitutes a view model. I have a class
that I use to wrap my model and alter the data slightly, but I am not sure
whether it constitutes a view model. What is necessary to be considered a
view model? Is it merely not supposed to have direct dependencies on the
view, so that the viewmodel does not know how the view uses its properties
and the view does not know what is in the viewmodel? and when the view
wants to update anything it just gives some abstract command that the
viewmodel takes and uses to update the model?
As I understand it in MVVM, I'm supposed to use properties on the view
that bind to properties on the viewmodel that bind to properties on the
model.
and in the reverse direction, I'm supposed to use commands from the view
to the viewmodel, which then can either uses Icommand to command the
model, or can just call public functions in the model to make changes to
it.
One confusing thing is that in the example of MVVM that I saw made it seem
like in MVVM the view should have no code behind other than perhaps
creating commands, but I don't see how I could do that in my current
project. I'm making a custom control using lots of controls that are
interacting on events.
how would I make one treeview expand on another treeview's expand without
using events?

No comments:

Post a Comment