Published on

Solving real world problems with MVVM

Published in: Technology
  • Be the first to comment

No Downloads
Total views
On SlideShare
From Embeds
Number of Embeds
Embeds 0
No embeds

No notes for slide
  • The Sword in the Stone about the magician Merlin and King Arthur
  • View has references to PresentationModelPresentationModel also coordinates control state changes (eg: enabled/disabled controls)Contains plumbing code for synchronization.NET Data binding was not yet ready for this
  • View  ViewModel : Binding to commands and dataViewModel: Abstraction of the View, Has no reference to the View (unlike MVP)ViewModel  View : Change notifcation: EventsViewModel  Model : Normal interaction
  • Caliburn.micro

    1. 1. Caliburn.Micro<br />Solving real word problems implementing MVVM<br /><br /><br />
    2. 2. Agenda<br />MVVM Frameworks<br />Caliburn(.Micro)<br />What is it?<br />Patterns<br />Features<br />
    3. 3. MVVM Frameworks<br />
    4. 4. MVVM Frameworks Explorer<br />Source:<br />
    5. 5. What is Caliburn?<br />
    6. 6. 6<br />
    7. 7. What is Caliburn?<br />“Caliburn is a set of libraries designed to aid in the development of WPF, Silverlight and WP7 applications”<br /><br />
    8. 8. Fact<br />Implementing a User Interface is easy<br />
    9. 9. Fact<br />Implementing a maintainable User Interface is hard<br />
    10. 10. Goals of Caliburn<br />Build WPF/SL/WP7 Applications in a TDD friendly way<br />Simplify usage of various UI design patterns in WPF/SL/WP7<br />Simplify common UI tasks<br />Provide solutions to common<br /> UI architecture problems<br />Remove the boilerplate code<br /> when building MVVM app’s<br />
    11. 11. It’s all about patterns...<br />
    12. 12. Presentation Model<br />Presentation Model coordinates changes in the Model<br />Presentation<br />Model<br />View calls operations<br />View<br />Model<br />Operations<br />Data<br />Model alerts the Presentation Model<br />View synchronizes <br />with PresentationModel<br />
    13. 13. Model – View – ViewModel<br />Change<br />notification<br />Presenter coordinates changes in the Model<br />ViewModel<br />View<br />Model<br />Commands<br />Data<br />View binds <br />to commands <br />and data<br />Model alerts the Controller <br />
    14. 14. Command<br />ICommand<br />Invoker<br />+ Execute()<br />+ CanExecute()<br />Command<br />Receiver<br />
    15. 15. Application Controller<br />“A centralized point for handling screen navigation and the flow of an application.” – Martin Fowler<br />
    16. 16. Service Locator<br />Service A<br />Class A<br />Locator<br />Service B<br />
    17. 17. Dependency Injection Container<br />Dependency<br />Injection<br />Container<br />Component<br />
    18. 18. Event Aggregator<br />Results Model<br />Criteria Model<br />hub<br />Publish<br />Handle<br />Publish<br />Handle<br />Advert Model<br />Recent Searches Model<br />
    19. 19. The application<br />
    20. 20. The Application<br />
    21. 21. The Application<br />No Code Behind<br />No Event Wireups<br />No Commands<br />No Data Binding<br />No Data Templates<br />No Async Programming<br />No Custom Controls<br />No 3rd Party Libraries<br />
    22. 22. Features<br />
    23. 23. Features Overview<br />Basic configuration and bootstrapping<br />Actions<br />Screens, Conductors and Composition<br />All about conventions<br />The Window Manager<br />The Event Aggregator<br />Coroutines<br />
    24. 24. Basic Configuration<br />Convention over Configuration<br />Limited amount of configuration needed<br />Simple naming convention to locate Views for ViewModels. <br />e.g. MyApp.ViewModels.MyViewModelMyApp.Views.MyView. <br />Bootstrapper<br />Should run at startup<br />Specifies the root view model(=Application Shell)<br />View Model First but can be changed<br />IoC<br />Has it’s own small IoC container<br />Can be replaced by the IoC of your choice(MEF, Unity,…)<br />
    25. 25. Demo- Basic Configuration<br />
    26. 26. Actions - Basics<br />Command implementation for Caliburn.Micro<br />Extend databinding to bind not only data but also methods<br />Leverages System.Windows.Interactivity for it’s trigger mechanism. <br />Use anything that inherits from TriggerBaseto trigger the sending of an action message(events, …)<br />No need to add a command class and/or property on VM<br />Allows:<br />Execution of methods<br />Passing data from the UI into methods<br />Synchronous/Asynchronous calls<br />
    27. 27. Action - Guards<br />Guard property <br />Handler: “SayHello” message<br />Guard property: “CanSayHello”<br />CM will observe changes in that property and re-evaluate the guard accordingly.<br />Based on INotifyPropertyChanged to refresh trigger availability<br />Can change the state of the bound control<br />E.g. change a button to disabled, hide a menu item,…<br />
    28. 28. Demo- Actions<br />
    29. 29. UI Lifecycle Management<br />Often using MVVM involves tricky UI lifecycle issues for various UI components<br />Activation<br />Deactivation<br />Shutdown<br />Caliburn.Micro handles this lifecycle with Screens, Conductors and Screen Collections<br />29<br />
    30. 30. UI Lifecycle Management<br />Screen<br />A statefulunit of work existing within the presentation tier of an application. <br />Has a lifecycle associated with it.<br />Screen Conductor<br />Enforces the Screen Activation Lifecycle <br />Activates screens. <br />Deactivates screens.<br />Allows graceful shutdown. <br />Screen Collection<br />Maintains the list of currently opened screens or documents<br />
    31. 31. UI Lifecycle Management<br />Conductor<br />Screen 1<br />Screen 2<br />Active<br />Active<br />Activate() Screen 2<br />Deactive() Screen 1<br />CanClose()<br />Returns True<br />Activate() Screen 2<br />
    32. 32. Demo- Simple Navigation<br />
    33. 33. Demo- Simple MDI<br />
    34. 34. Conventions<br />Removes the need to write boiler plate code<br />Fully customizable<br />Can be turned off if you hate them<br />On by default<br />Conventions for<br />View/ViewModel resolution<br />Data binding<br />Action binding<br />
    35. 35. Demo- Conventions<br />
    36. 36. Window Manager<br />Provides a View-Model-centric way of displaying Windows (ChildWindow in SL and Window in WPF). <br />Available methods<br />ShowDialog<br />ShowWindow<br />ShowPopup<br />Uses a Conductor under the hood<br />
    37. 37. Demo – Window Manager<br />
    38. 38. Event Aggregator<br />Communicate between objects in a loosely coupled way<br />Follows a bus-style pub/sub model. <br />Uses weak references<br />Publishes on the UI thread. <br />
    39. 39. Demo – Event Aggregator<br />
    40. 40. Coroutines<br />Wikipedia:<br />“In computer science, coroutines are program components that generalize subroutines to allow multiple entry points for suspending and resuming execution at certain locations. Coroutines are well-suited for implementing more familiar program components such as cooperative tasks, iterators, infinite lists and pipes.”<br />
    41. 41. Coroutines<br />Introduces asynchronous programming in a simple way.<br />Build on top of iterators.<br />2 required actions<br />Implement the IResult interface on some class, representing the task you wish to execute<br />Yield instances of IResult from an Action<br />
    42. 42. Coroutines<br />Allows you to execute a method, pause it’s execution, do something else, come back and resume execution where you left off. <br />Extremely powerful in task-based programming<br />
    43. 43. Coroutines<br />Silverlight example: <br />Dynamically download and show screens not part of the main package. <br />
    44. 44. Coroutines<br />Show “Loading” indicator<br />Load Screen()<br />yieldreturn<br />yieldreturn<br />yieldreturn<br />yieldreturn<br />Asynchronously download the external package<br />Hide“Loading” indicator<br />Navigate to a particular screen inside the dynamic module<br />
    45. 45. Demo - Coroutines<br />
    46. 46. TODAY’s TALK<br />Remember! <br />Still a lot to discover...<br />CALIBURN<br />
    47. 47. Conclusions<br />Caliburn.Micro is clean and simple<br />Allows you to create very rich applications with a strong focus on maintainability and reuse<br />A LOT of UI principles are applied in Caliburn.Micro<br />Also check it’s big brother Caliburn<br />“If you don’t like the code, use it as a learning tool”<br />47<br />