Presentation Model
      The First Contact
Agenda
   Quick Introduction
   Why should I care about it?
   View Model
   XAML
   Data Binding
   ViewModel Base
   Commands
   Validation
   Data Templates
   Resource Systems
   MVVM Framework
   How do I do…?
Quick Introduction: Presentation Patterns
UI Patterns Comparison
 Passive View
 Supervising Controller
 Presentation Model
Presentation Model
“Probably the most annoying part of the Presentation Model is the
synchronization between Presentation Model and view. It’s simple code
to write, but I always like to minimize this kind of boring repetitive
code.
Ideally some kind of framework could handle this, which I’m hopping
will happen some day with technologies like .NET’s data binding.”
                                                        Martin Fowler, 2004.
Model – View – ViewModel
 Technology specific implementation of the PM
 Separation of Markup and Code
 Behaviour of the Application
 Look and Feel
 Tool Support
“Once a developer becomes comfortable
with WPF and MVVM, it can be difficult
to differentiate the two. ”. Josh Smith, MVVM Guru
Why should I care about it?
 Order vs. Chaos
 Technology Choice
 Loose Coupling
 Testability (DEMO)
 Maintainable Code
 Blendability (DEMO)
 It is cool
<Disclaimer>
 No Solution is Perfect
 Different Approaches
    View-Centric
    ViewModel Centric




                           </Disclaimer>
View Model
 Separation of Concerns
 Enables code reuse
 State + Operations
 Provides a Bindable Surface
 Not Dependent on the View
 Typically One-To-One ViewModel to View
   One-To-Many is very common though
XAML
 Humble View
 Plays nicely with Data Binding
  capabilities
Data Binding
 Binding Expression
 Binding Direction
 Binding to Elements
 Binding to Templates
 RelativeSource
DEM
O
Commands
 Delegate Command vs. Relay Command (DEMO)
 Uses WPF Behaviours capabilities
 Map Events to Commands (DEMO)
DEM
O
Validation
 Implemented on ViewModel, not in Model Class
DEM
O
Messaging
 Uses a light message bus to communicate between components
 Publish/Subscribe
 Frameworks (MVVM Light) (DEMO)
DEM
O
MVVM Light Toolkit
ViewModel Locator
 Repository of ViewModels
 Uses WPF DataTemplate Capabilities
 One View per ViewModel
 MVVM Light
DEM
O
MVVM Light Toolkit
Trade-Offs
 Agregate Model vs Proxy Property
 Start animation on the View through ViewModel
 How to close a window
 Clean and Shutdown
 Handle Navigation
 Add your own topic to be discussed…
And continues…
Not used only with WPF/Silverlight:
 ASP.NET MVC
 Knockout.js
 Java frameworks (RLY?)




                                      To Far and Beyond… That’s it ;-)

Presentation Model

  • 1.
    Presentation Model The First Contact
  • 2.
    Agenda  Quick Introduction  Why should I care about it?  View Model  XAML  Data Binding  ViewModel Base  Commands  Validation  Data Templates  Resource Systems  MVVM Framework  How do I do…?
  • 3.
  • 4.
    UI Patterns Comparison Passive View  Supervising Controller  Presentation Model
  • 5.
    Presentation Model “Probably themost annoying part of the Presentation Model is the synchronization between Presentation Model and view. It’s simple code to write, but I always like to minimize this kind of boring repetitive code. Ideally some kind of framework could handle this, which I’m hopping will happen some day with technologies like .NET’s data binding.” Martin Fowler, 2004.
  • 6.
    Model – View– ViewModel  Technology specific implementation of the PM  Separation of Markup and Code  Behaviour of the Application  Look and Feel  Tool Support
  • 7.
    “Once a developerbecomes comfortable with WPF and MVVM, it can be difficult to differentiate the two. ”. Josh Smith, MVVM Guru
  • 8.
    Why should Icare about it?  Order vs. Chaos  Technology Choice  Loose Coupling  Testability (DEMO)  Maintainable Code  Blendability (DEMO)  It is cool
  • 9.
    <Disclaimer>  No Solutionis Perfect  Different Approaches  View-Centric  ViewModel Centric </Disclaimer>
  • 10.
    View Model  Separationof Concerns  Enables code reuse  State + Operations  Provides a Bindable Surface  Not Dependent on the View  Typically One-To-One ViewModel to View  One-To-Many is very common though
  • 11.
    XAML  Humble View Plays nicely with Data Binding capabilities
  • 12.
    Data Binding  BindingExpression  Binding Direction  Binding to Elements  Binding to Templates  RelativeSource
  • 13.
  • 14.
    Commands  Delegate Commandvs. Relay Command (DEMO)  Uses WPF Behaviours capabilities  Map Events to Commands (DEMO)
  • 15.
  • 16.
    Validation  Implemented onViewModel, not in Model Class
  • 17.
  • 18.
    Messaging  Uses alight message bus to communicate between components  Publish/Subscribe  Frameworks (MVVM Light) (DEMO)
  • 19.
  • 20.
    ViewModel Locator  Repositoryof ViewModels  Uses WPF DataTemplate Capabilities  One View per ViewModel  MVVM Light
  • 21.
  • 22.
    Trade-Offs  Agregate Modelvs Proxy Property  Start animation on the View through ViewModel  How to close a window  Clean and Shutdown  Handle Navigation  Add your own topic to be discussed…
  • 23.
    And continues… Not usedonly with WPF/Silverlight:  ASP.NET MVC  Knockout.js  Java frameworks (RLY?) To Far and Beyond… That’s it ;-)

Editor's Notes