tags:

views:

41

answers:

1

When I want to implement ViewModel I should cut everything c# code from my Silverlight code behind(next delete .cs file and leave only .xaml file) and paste it in new class in new folder ViewModel ? It is good way of separate View from logic ?

+1  A: 

When I want to implement ViewModel I should cut everything c# code from my Silverlight code behind

Not necessarily... MVVM isn't about "no code-behind". Sometimes it is useful or even necessary to use code-behind, if you're doing something that is specific to the view and is unrelated to the model/ViewModel.

and paste it in new class in new folder ViewModel

Definitely not ! If you do that, you're completely missing the point of MVVM. The ViewModel should have absolutely no knowledge of the View, so clearly you can't write the same kind of code in the ViewModel and in the code-behind...

I suggest you read some articles about MVVM, like this one by Josh Smith. The same Josh Smith also published a book about MVVM recently, which provides a good overview of MVVM

Thomas Levesque
Tnx for article, hope it help me ;) So in ViewModel i should write class which will maintenance the data from Model? And in View, data which was query in ViewModel should be binding to controls?
netmajor
The ViewModel accesses the model, and exposes properties and commands to which the View can bind
Thomas Levesque
That resolve my doubts. Tnx Thomas :)
netmajor