1 / 20

An Introduction to the Model-View-ViewModel Pattern

An Introduction to the Model-View-ViewModel Pattern. Seriously? Another MV* Pattern? BrianGenisio@Gmail.com. How I Got Into MVVM. The Healthcare Application. Screenshot of WebStation. The Generalized Problem. What We Want. How Do We Achieve that?. View. ViewModel. Model. Bindings.

Download Presentation

An Introduction to the Model-View-ViewModel Pattern

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. An Introduction to the Model-View-ViewModel Pattern Seriously? Another MV* Pattern? BrianGenisio@Gmail.com

  2. How I Got Into MVVM

  3. The Healthcare Application • Screenshot of WebStation

  4. The Generalized Problem

  5. What We Want

  6. How Do We Achieve that? View ViewModel Model

  7. Bindings A More Complete Diagram Unit Tests Integration Tests View XAML, Code Behind Actions Behavior ViewModel Properties, Commands, View Logic Events Data Model Service Proxies Web

  8. Emerging Technology We’re still trying to figure out the Best Practices

  9. Standing on the Shoulders of Giants • MVC • MVP • Presenter Model • Martin Fowler • Josh Smith • John Gossman • Sean Wildermuth

  10. Mini Patterns The Gears That Drive The Machine

  11. NotifyPropertyChanged public interface INotifyPropertyChanged { event PropertyChangedEventHandler PropertyChanged; }

  12. Command Pattern public interface ICommand { bool CanExecute(object param); void Execute(object param); event EventHandler CanExecuteChanged; } public class DelegateCommand : ICommand { public DelegateCommand( Action<object> command, Predicate<object> canExecute); }

  13. Event Aggregator Pattern

  14. Attached Behaviors <TextBlock FontSize=“32” Foreground=“Red” Width=“200” Behaviors:Trimming.Text=“…” /> TextBlock FontSize Foreground Width … Trimming Behavior

  15. MVVM Guidelines 1. Reduce or eliminate your code-behind 2. Bind all of your UI inputs/outputs to your ViewModel 3. Implement INotifyPropertyChanged on your ViewModel 4. Put your logic into the ViewModel OR Controller 5. Do not put any view state into the model 6. Only bind to a model object if there is no view-specific info 7. When testing, treat ViewModel as the Real UI 8. Avoid events. Use commands instead

  16. Third Party Support • Prism • Caliburn • Silverlight FX • MVVM Toolkit • SL3?

  17. Demo -- Recipe Box

  18. Who Creates the ViewModel? XAML View Constructor Other ViewModel Marriage Dependency Injection

  19. Silverlight [Unit|Integration|Functional] Testing • Nunit/Moq • Silverlight UT

  20. Contact Info BrianGenisio@Gmail.com http://HouseOfBilz.com http://Twitter.com/BrianGenisio http://speakerrate.com/briangenisio

More Related