Learning WPF M-V-VM

For the last few months I’ve been studying M-V-VM and other WPF UI design patterns.

I have selected M-V-VM as my UI design pattern of choice for the soon to be released Ocean framework and code generation system.

I have read much of what Microsoft Partner Architect John Gossman, members of the WPF Disciples have published and specifically what my great friend and Microsoft & Code Project MVP Josh Smith has written on the UI design patterns.

Without any doubt, the best and clearest example of WPF M-V-VM I’ve seen is in Josh’s latest achievement, Crack.NETIf you want to learn M-V-VM from an expert, download Crack.NET source and study Josh’s masterpiece.

Applied

I’m sitting here at the Silicon Valley Code Camp having just taught a M-V-VM for WPF LOB session.   The applications I presented were all 100% testable.  The main application that has all the unit tests, can be run without ever displaying any UI.  It is amazing the power that M-V-VM delivers with such simplicity.  

I need to make a few videos and write up a blog post and I’ll share the code with you after next weekend.

I’m finishing up Ocean’s UI and it uses M-V-VM.

Below is a slide from the presentation.  It covers the layers found in an WPF LOB application.

WPFLOBMVVM

Raleigh Code Camp

Next weekend, 15 Nov 2008, I’ll be in Raleigh, NC for the annual fall RDU Code Camp.  I’ll be launching Ocean at this code camp and will be doing several other sessions as well as being available in the Open Spaces.  See you there!!

Close

Have a great day,

Just a grain of sand on the worlds beaches.

29 Responses to “Learning WPF M-V-VM”

  1. Learning WPF M-V-VM | DavideZordan.net Says:

    [...] out this interesting article by “Karl on WPF” about LOB using WPF and the M-V-VM [...]

  2. Dew Drop - Weekend Edition - November 8-9, 2008 | Alvin Ashcraft's Morning Dew Says:

    [...] Learning WPF M-V-VM (Karl Shifflett) [...]

  3. Patrón Model-View-ViewModel en aplicaciones de negocio en WPF « Carliños Blog Says:

    [...] Otro interesante artículo en “Karl on WPF” sobre el uso del patrón Model-View-ViewModel en las aplicaciónes de negocio [...]

  4. qntmfred Says:

    I’m glad your diagram includes a business layer. It seems to me to be a pretty critical component, and most descriptions of the pattern I’ve seen have left this part out, which has thrown me off somewhat.

    I’ll be making the trip to RDU from Charlotte next weekend, looking forward to it.

  5. 2008 November 10 - Links for today « My (almost) Daily Links Says:

    [...] Shifflett on Learning WPF M-V-VM with a great diagram of the application [...]

  6. desfen Says:

    Hello Karl, great post ! I do have to wonder why it’s your datamodels that are implementing IDataErrorInfo. I tend to let the viewmodels do that, since they are closest the view. Or am I missing something ?

    Thanks for all the great content lately !

  7. desfen Says:

    Harrumph ! Note to self: never type before thinking/reading. :-)
    After reading your WPF Business App Series I understand. Guess it’s back to my code in order to refactor :-)

  8. Karl Shifflett Says:

    desfen,

    I’ll be sure to cover this question in my article.

    Cheers,

    Karl

  9. Building a WPF Application: Part 4 - Christopher Bennage Says:

    [...] Karl Shifflett posted recently on the M-V-VM pattern, and also directs some attention (rightly so) to Josh Smith's [...]

  10. vinsibal Says:

    Really looking forward the videos and posts on MVVM.

  11. Karl Shifflett Says:

    vinsibal,

    Thank you for your kind words. I too am looking forward to making them.

    Cheers,

    Karl

  12. dotnetchimp Says:

    This is really awesome stuff Karl…your a .net Saint…cant wait to get my paws on it.
    Regards

  13. Silverlight Travel | Lernen WPF M-V-VM Says:

    [...] MVVM scheint sich für WPF durch zu setzen. [...]

  14. johnnysbug Says:

    Karl,

    I saw your post recently on the WPF Disciples group about handling MessageBoxes in an MVVM. Have you had any further insight on the matter?

    My approach has initially been to have the ViewModel raise an event that the View subscribes to. If the message requires feedback, there is a Result in the MessageEventArgs that the View can set (right now it is of type MessageBoxResult which I was hesitant to use because of not wanting to tie the ViewModel to anything UI specific).

    MessageEventArgs also has things that allow the View to tailor the message box appropriately, such as if it is a Yes/No message, or just an Ok, or whether to be a Warning, etc..

    I am going to stick with the approach for the meantime until something better is cooked up, although folks here at my worksite frown against giving the ViewModel any knowledge of UI specifics.

    Its good to know you guys are also wondering about how to solve this.

    Best,
    Jonathan

  15. Karl Shifflett Says:

    Johathan,

    First, thanks for your great comments.

    Events: This is EXACTLY what I’m doing. Corrado from WPF Disciples is doing the same.

    As far as your folks at work. I think it’s good to listen and understand different approaches. Other WPF developers I respect have a raised eye-brow over events. This is OK.

    I think this is another reason Dr. WPF calls this, M-V-poo.

    I don’t see any different between raising an event and the other approaches. In my humble opinion, Events don’t imply knowledge or relationship. It implies a decoupling.

    I’m with you. If I find another published technique that is simple to understand and implement and is better than events, then, I’ll be all over it.

    Cheers,

    Karlo

  16. UI Design Patterns Presentation Code + Slide Deck - Joe's Blog Says:

    [...] Martin Fowler MVCMartin Fowler MVPASP.NET MVP & Other Patterns Karl Shifflett MVVM [...]

  17. 1kevgriff Says:

    Karl,
    I saw you present this past weekend at the Raleigh Code Camp. I was the guy you gave the MSDN subscription too in the first session. I just wanted to say thank you. Not just for the MSDN subscription, but for inspiring me. I’m still very young in my career, and you were a great inspiration of the type of developer I want to be. The company I work for does quite a bit of “presentational” type applications (training applications, kiosks, etc), and I believe that WPF/Silverlight could be a major improvement in the way we write our applications. The major hurdle I see is teaching our designers who normally work in Flash to work in XAML and Blend.

    I’m going to make sure I go back and read your past blog posts.

    Thanks again,
    Kevin Griffin

  18. Karl Shifflett Says:

    Kevin,

    Thank you for your kind works, it was a true pleasure and honor to be part of Code Camp.

    I wish you and your company the very best in your application development.

    Best to you,

    Karl

  19. dotnetchimp Says:

    Karl

    You mentioned you would be releasing Ocean at the raleigh code camp…is that still on tha cards?

    Thanks

  20. Karl Shifflett Says:

    DotNetChimp,

    Yes Ocean is in the cards. Chris Love and I changed my sessions at Raleigh two days before Code Camp to WPF LOB and MVVM.

    I’m finishing up a series on MVVM and will release another version of XAML Power Toys this weekend, then Ocean.

    Cheers and thanks for asking!

    Karl

  21. WMOC#26 - Microsoft PDC Roundup - Service Endpoint Says:

    [...] Karl Shifflett – Learning WPF M-V-VM [...]

  22. davidjjon Says:

    Hi Karl – I am really anixous to get my hands on the Ocean Framework, especially from a Silverlight viewpoint.

    David Roh
    JK@SilverlightAzure.com

  23. Karl Shifflett Says:

    David,

    Working very hard on this. We have spent the last week tracing down memory leaks in MVVM. This has nothning to do with Ocean. We got a breakthrough in the last day.

    I’m working SUPER hard on the MVVM articles and Ocean.

    Cheers,

    Karl

  24. asesta Says:

    Hi Karl,

    I just finished up the third section of your WPF LOB series (and it was great). Did you have to make a lot of changes to your core classes to get them to work with MVVM? I noticed your above slide shows the business layer separate from the model.

    Thanks,

    Al

  25. Karl Shifflett Says:

    Al,

    Thank you for your kind words.

    I have rebranked the Core library OceanFramework and will be releasing soon.

    I really didn’t have to make many changes.

    Cheers,

    Karl

  26. Jerry Lin Says:

    Hi Karl,

    Thanks for taking the time write all these articles on M-V-VM, as the thought of reducing code in the code-behind alone sounds promising. Just one question though, why did you choose to have the ViewModels implement INotifyPropertyChanged instead of making properties with change notifications full-blown DependencyProperties?

    Jerry

  27. Karl Shifflett Says:

    Jerry,

    Thanks for your appreciation of the hard work.

    My two cents: The question of DP’s vs. INPC has been discussed in many circles.

    I like INPC because its simpler to implement. Serializing DP’s has its challenges. Also is dependent on WPF. So moving the ViewModel to Silverlight without code changes is just a recomplile verses possible code modifications.

    Best to you,

    Karl

  28. koo9 Says:

    while MV VM pattern try to separat the UI and business logic, i have a quick question here. how to relay the sender information from the UI to the business logic layer? and I think the MV VM people will say no to this since the VM should not know anything about the UI. in that case, how to retrieve the underlying dataitem binded to the UI control? is there an easy way to send the binded data item back without looking up the item through some sort of Id sent back from commandparamter?

    Kevin

  29. koo9 Says:

    never mind, I can bind the object to the commandparameter like this CommandParameter=”{Binding}”

Leave a Reply

You must be logged in to post a comment.