Understanding The MVVM Pattern (TechDays Belgium)

6,976 views

Published on

The Model-View-ViewModel pattern (also called MVVM) is a hot topic in today’s Silverlight and WPF world. This pattern facilitates modern development techniques such as separation of concerns (decoupling), unit testing and test driven development, work with modern tools such as Visual Studio 2010, Expression Blend and more.
In this session, Laurent (a user and promoter of MVVM since 2006) will introduce this pattern to you with many demos. We will talk about the basic components of a modern Silverlight or WPF application, and of additional helpers that will make your life as a developer much easier.

Published in: Technology
0 Comments
3 Likes
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total views
6,976
On SlideShare
0
From Embeds
0
Number of Embeds
97
Actions
Shares
0
Downloads
264
Comments
0
Likes
3
Embeds 0
No embeds

No notes for slide
  • Demo of connection to WCF service, fails in BlendShow how to attach to processIdentify problemIsInDesignMode
  • Demo of connection to WCF service, fails in BlendShow how to attach to processIdentify problemIsInDesignMode
  • Demo of connection to WCF service, fails in BlendShow how to attach to processIdentify problemIsInDesignMode
  • Demo of connection to WCF service, fails in BlendShow how to attach to processIdentify problemIsInDesignMode
  • Demo of connection to WCF service, fails in BlendShow how to attach to processIdentify problemIsInDesignMode
  • Understanding The MVVM Pattern (TechDays Belgium)

    1. 1. Understanding the MVVM pattern Laurent Bugnion Senior User Experience Integrator IdentityMine http://[blog|www].galasoft.ch
    2. 2. What is MVVM? • A weird acronym • Model – View – ViewModel • « MVVM in a SLOOB with SLUT » • Woven into WPF/SL • Some confusion: • MVVM is really just the pattern • The rest are helpers, practices, etc
    3. 3. The MVC pattern Model View Controller
    4. 4. The Passive View pattern Model View Controller
    5. 5. The Presentation Model pattern Model View DataBinding Presentation Model (ViewModel)
    6. 6. Blendability • Testability, Maintainability, Blendability • “The ability to be edited in Blend” • (and Visual Studio designer…) • Differentiate code in design and runtime • Create design time data
    7. 7. Hello MVVM (and Hi Blend)
    8. 8. Bridging the gap View DataBinding Commands Messages ViewModel Model
    9. 9. Bridging the gap View View Messages ViewModel ViewModel View Messages + callback ViewModel
    10. 10. Commands • “Point of entry” for a method” • Can be data bound • ICommand interface • Execute method • CanExecute method • CanExecuteChanged event handler
    11. 11. Commands and RelayCommands
    12. 12. RelayCommands RelayCommand MyCommand = new RelayCommand( () => ..., () => true | false); RelayCommand<T> MyGenericCommand = new RelayCommand<T>( p => ..., p => true | false);
    13. 13. Messaging • Should be simple by default • Possible to open filtered channels • To a target Type (or an Interface) • With a Token • With various Messenger instances • No constraints at all
    14. 14. Messaging
    15. 15. Messaging Messenger.Default.Register<T>( this, p => DoSomething(p)); Messenger.Default.Send<T>(p);
    16. 16. MVVM Light Toolkit • “Breaking the monotony” • http://www.galasoft.ch/mvvm/getstarted • http://mvvmlight.codeplex.com • V3 released at MIX10 • Keep it small • Keep it simple
    17. 17. MVVM Light Libraries V3 • ESSENTIALS • RelayCommand • Messenger • ViewModelBase • EXTRAS • EventToCommand • DispatcherHelper
    18. 18. MVVM Light Tools V3 • Project templates (VS + Blend) • Item templates (VS + Blend) • Code snippets
    19. 19. MVVM Light Toolkit, Unity, Blendability
    20. 20. Flaws of MVVM • Too much code needed • INotifyPropertyChanged • Commands • Some operations are tricky (set focus…) • Not applicable to ASP.NET, etc • Message to community is not clear
    21. 21. Debunking the myths • “No code in the code behind” • “If you put code in the View's code-behind, the MVVM police will take your family away” • “No need for converters” • “MVVM is only suitable for big projects” • “MVVM costs performance” • “MVVM is complex / makes my head hurt”
    22. 22. Debunking the myths • “I don’t need separation because I don’t have a designer” • “You cannot use MVVM with other patterns” • “MVVM will make you rich and attractive”
    23. 23. MVVM on the Windows Phone 7
    24. 24. http://blog.galasoft.ch http://www.galasoft.ch/mvvm/getstarted @LBugnion

    ×