Take a look at the following article by Josh Smith: http://www.codeproject.com/KB/WPF/TreeViewWithViewModel.aspx
IMHO if you are using WPF then you make your life easier (in the long run) by following the MVVM pattern. Others will disagree ;-)
Fintanv:IMHO if you are using WPF then you make your life easier (in the long run) by following the MVVM pattern. Others will disagree ;-)
The question is which MVVM pattern? There are several variants with different pre-conditions and consequences.
Many of the MVVM pattern variants assume an anemic Model, such as a bunch of DTO/proxy/entity objects you get back from calling a service or something like EF or L2S. Those variants require that you do a lot of work in the VM to overcome the lack of functionality in the Model, and that's fine.
However, CSLA .NET ensures that your Model is far from anemic. In fact, it is incredible rich, with the DataTable being the only thing I know of that comes close. Fortunately there are variants of MVVM where the VM exposes the Model as a property, along with various methods (commands) that can be bound to buttons, etc.
That type of MVVM implementation works really well with CSLA .NET.
On the other hand, if you use one of the "anemic model" variants of MVVM with CSLA objects, you'll have to do more work in your VM or sacrifice a lot of functionality. Your VM could have to implement and delegate (bi-directionally) all the data binding interfaces, authorization, business rule and other functionality that is built directly into CSLA.
In either case (anemic or rich Model), if your object graph is complex (parent-child-grandchild-etc) your VM can become incredibly complex very rapidly, as you try to flatten or duplicate the shape of the Model.
I've had people argue that the point of the VM is to "reshape" the Model for the UI. And I agree that if your Model was not designed using good OOD (is data-centric rather than respnsibility-driven) then your VM will probably have to do that - which is really lame, and simply means you did a crappy job with your object model.
On the other hand, if you use responsibility-driven design for your business objects, your object model should naturally follow the shape of the use case, as should the UI. Since they follow the same use case, the objects should already be the right shape.
Lots of opinion there, but that's my current way of thinking about MVVM.
Yes it is good. Some variants work really well with CSLA. Other variants cause you to do so much work that I can't possibly imagine it is of long-term benefit.
Copyright (c) Marimer LLC