DataModel-View-ViewModel pattern series


I thought I should add a post with the full list of posts in the D-V-VM pattern. They are:

DataModel-View-ViewModel pattern: 1 (overview)

DataModel-View-ViewModel pattern: 2 (first implementation of DataModel class)

DM-V-VM part 3: A sample DataModel

DM-V-VM part 4: Unit testing the DataModel

DM-V-VM part 5: Commands

DM-V-VM part 6: Revisiting the data model

DM-V-VM part 7: Encapsulating commands

DM-V-VM part 8: View Models

Comments (29)

  1. Dan Crevier has series of posts on the DM-V-VM pattern, including how to implement it and how ot test

  2. Bryant Likes says:

    Thanks! Now you just need a DM-V-VM tag so that all your posts come up in one place. 🙂

  3. Houman says:

    Thanks this was great.  

    I specially liked the way you injected control into the StockModel [StockModel(symbol, IStockQuoteProvider)]

    To be honest, I had some difficulty grasbing the why & how of the ActivateModel.  I had to really think about it, but I think I get it now…with that said, would you please give an example of why you needed to do reference counting?  In other words: For which scenarios the ActiviateModel you described isn’t good enough?

    Thanks again.

    Houman

  4. I may have included one of those in one of my link roundups, but this is a topic very dear to my heart

  5. One example scenario where I needed ref counting in the activation was in Max when we had nested views where the inner view’s template was chosen programmatically based on the model state. Both the outer view and inner view needed to activate the model. If you don’t need this, no need to add the complexity.

  6. Suhas Sane says:

    Thanks for a post, it is very good. Currently I am working on creating a back end accounting application with WPF. Since we anticipate many calls to service layer (WCF), I liked the concept of DataModel. It was curious that the constructor of the viewModel DataModel is doing actual data extraction. I would have thought you will have separate GetData Method. Usually I try to perform minimal task in constructors.

    I am also struggling about how to write an automated unit test for the PortfolioViewModel equivalent. To test the behavior of AddCommandModel and RemoveCommandModel etc. Any information you can provide in that domain can be helpful.

  7. Actually the data extraction really happens when the model is activated.

    To unit test AddCommandModel/RemoveCommandModel, you can set up some test data in PortfolioViewModel. Then, you can get the commands through the PropertyViewModel accessors and call OnQueryEnabled and OnExecute with different parameters to try it out. In cases where you need to get to private methods and data, use PrivateObject or PrivateType.

  8. Suhas Sane says:

    I tried to use your suggestion to call OnQueryEnabled  and OnExecute  directly. I keep getting error "The type CanExecuteRoutedEventArgs has no constructors defined".  I am not able to find any sample which directly instantiates this class.

    My aim is to create a console application to test the behavior of presenter. I guess if I create a windows based application I can use command binding and test this via Command object. But not sure how to do this in Console app.

  9. You can use Visual Studio’s PrivateObject helper class to help out:

    Type[] types = { typeof(ICommand), typeof(object) };

    object[] param = { myRoutedCommand, null };

    PrivateObject privateCanExecuteArgs = new PrivateObject(typeof(CanExecuteRoutedEventArgs), types, param);

    CanExecuteRoutedEventArgs canExecuteArgs = (CanExecuteRoutedEventArgs)privateCanExecuteArgs.Target;

    You can do this from a command line app.

  10. Mike Brown says:

    Regarding multiple parameters for the CommandModel: what if we set the ViewModel as the parameter for the CommandModel. This way the CommandModel can be the link between the ViewModel and the DataModel and can validate against N number of values.

  11. Yes, that would definitely work. If you do things through an interface, it will keep the command from being specific to one view model.

  12. I’ve been meaning to document how I wrapped the Twitter API … in 4.5 seconds. There is a very powerful

  13. I've been meaning to document how I wrapped the Twitter API … in 4.5 seconds. There is a very powerful

  14. Introduction I've been posting a lot about Silverlight lately, but hey, here is a WPF post, and about

  15. Tonight I presented for the Dayton .Net Developers Group on WPF. Unlike my previous Lap Around WPF @

  16. In this post (of what may become a series of posts if I find some interest from the community) I compare

  17. First I'd like to say that I'm stoked about the work the Prism team has been doing.  I have

  18. This post is based on an interpretation of a pattern called View-View Model-Document or View-View Model

  19. Elise's blog says:

    Après avoir participé à quelques projets WPF depuis maintenant un peu plus d’un an, je suis dans une

  20. Elise's blog says:

    Après avoir participé à quelques projets WPF depuis maintenant un peu plus d’un an, je suis dans une

  21. Tre Simpla says:

    Checking out DataModel ViewModel patterns.

  22. Table of Contents Since my last post on building ChumChase, I've had a couple of projects that have

  23. Table of Contents Since my last post on building ChumChase, I've had a couple of projects that have

  24. Table of Contents Since my last post on building ChumChase, I've had a couple of projects that have

  25. ReBitting says:

    Serie Tutorial Pattern DM-V-VM

  26. Вторая часть из серии постов, в которых мы последовательно пройдем все этапы соз

  27. In this article I will explain how to implement MVVM pattern in Silverlight. I was very overjoyed when

  28. #.think.in says:

    #.think.in infoDose #21 (10th Mar – 15th Mar)