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.NET. If 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.
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.




November 8, 2008 at 5:34 pm |
[...] out this interesting article by “Karl on WPF” about LOB using WPF and the M-V-VM [...]
November 8, 2008 at 9:15 pm |
[...] Learning WPF M-V-VM (Karl Shifflett) [...]
November 9, 2008 at 12:24 pm |
[...] Otro interesante artículo en “Karl on WPF” sobre el uso del patrón Model-View-ViewModel en las aplicaciónes de negocio [...]
November 9, 2008 at 4:08 pm |
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.
November 10, 2008 at 2:46 am |
[...] Shifflett on Learning WPF M-V-VM with a great diagram of the application [...]
November 10, 2008 at 5:44 am |
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 !
November 10, 2008 at 5:59 am |
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
November 10, 2008 at 8:39 am |
desfen,
I’ll be sure to cover this question in my article.
Cheers,
Karl
November 10, 2008 at 8:59 am |
[...] Karl Shifflett posted recently on the M-V-VM pattern, and also directs some attention (rightly so) to Josh Smith's [...]
November 10, 2008 at 1:03 pm |
Really looking forward the videos and posts on MVVM.
November 10, 2008 at 10:50 pm |
vinsibal,
Thank you for your kind words. I too am looking forward to making them.
Cheers,
Karl
November 11, 2008 at 8:47 am |
This is really awesome stuff Karl…your a .net Saint…cant wait to get my paws on it.
Regards
November 11, 2008 at 10:22 pm |
[...] MVVM scheint sich für WPF durch zu setzen. [...]
November 12, 2008 at 10:50 am |
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
November 12, 2008 at 11:12 am |
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
November 14, 2008 at 3:00 am |
[...] Martin Fowler MVCMartin Fowler MVPASP.NET MVP & Other Patterns Karl Shifflett MVVM [...]
November 17, 2008 at 10:27 am |
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
November 17, 2008 at 10:29 am |
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
November 18, 2008 at 10:37 am |
Karl
You mentioned you would be releasing Ocean at the raleigh code camp…is that still on tha cards?
Thanks
November 19, 2008 at 12:15 am |
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
November 21, 2008 at 12:52 am |
[...] Karl Shifflett – Learning WPF M-V-VM [...]
November 25, 2008 at 10:19 am |
Hi Karl – I am really anixous to get my hands on the Ocean Framework, especially from a Silverlight viewpoint.
David Roh
JK@SilverlightAzure.com
November 25, 2008 at 12:00 pm |
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
December 5, 2008 at 2:35 pm |
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
December 6, 2008 at 8:55 am |
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
January 5, 2009 at 4:16 pm |
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
January 5, 2009 at 9:11 pm |
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
March 16, 2009 at 9:55 am |
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
March 16, 2009 at 10:05 am |
never mind, I can bind the object to the commandparameter like this CommandParameter=”{Binding}”