7. What is Caliburn? “Caliburn is a set of libraries designed to aid in the development of WPF, Silverlight and WP7 applications” http://caliburnmicro.codeplex.com
10. Goals of Caliburn Build WPF/SL/WP7 Applications in a TDD friendly way Simplify usage of various UI design patterns in WPF/SL/WP7 Simplify common UI tasks Provide solutions to common UI architecture problems Remove the boilerplate code when building MVVM app’s
12. Presentation Model Presentation Model coordinates changes in the Model Presentation Model View calls operations View Model Operations Data Model alerts the Presentation Model View synchronizes with PresentationModel
13. Model – View – ViewModel Change notification Presenter coordinates changes in the Model ViewModel View Model Commands Data View binds to commands and data Model alerts the Controller
21. The Application No Code Behind No Event Wireups No Commands No Data Binding No Data Templates No Async Programming No Custom Controls No 3rd Party Libraries
23. Features Overview Basic configuration and bootstrapping Actions Screens, Conductors and Composition All about conventions The Window Manager The Event Aggregator Coroutines
24. Basic Configuration Convention over Configuration Limited amount of configuration needed Simple naming convention to locate Views for ViewModels. e.g. MyApp.ViewModels.MyViewModelMyApp.Views.MyView. Bootstrapper Should run at startup Specifies the root view model(=Application Shell) View Model First but can be changed IoC Has it’s own small IoC container Can be replaced by the IoC of your choice(MEF, Unity,…)
26. Actions - Basics Command implementation for Caliburn.Micro Extend databinding to bind not only data but also methods Leverages System.Windows.Interactivity for it’s trigger mechanism. Use anything that inherits from TriggerBaseto trigger the sending of an action message(events, …) No need to add a command class and/or property on VM Allows: Execution of methods Passing data from the UI into methods Synchronous/Asynchronous calls
27. Action - Guards Guard property Handler: “SayHello” message Guard property: “CanSayHello” CM will observe changes in that property and re-evaluate the guard accordingly. Based on INotifyPropertyChanged to refresh trigger availability Can change the state of the bound control E.g. change a button to disabled, hide a menu item,…
29. UI Lifecycle Management Often using MVVM involves tricky UI lifecycle issues for various UI components Activation Deactivation Shutdown Caliburn.Micro handles this lifecycle with Screens, Conductors and Screen Collections 29
30. UI Lifecycle Management Screen A statefulunit of work existing within the presentation tier of an application. Has a lifecycle associated with it. Screen Conductor Enforces the Screen Activation Lifecycle Activates screens. Deactivates screens. Allows graceful shutdown. Screen Collection Maintains the list of currently opened screens or documents
34. Conventions Removes the need to write boiler plate code Fully customizable Can be turned off if you hate them On by default Conventions for View/ViewModel resolution Data binding Action binding
36. Window Manager Provides a View-Model-centric way of displaying Windows (ChildWindow in SL and Window in WPF). Available methods ShowDialog ShowWindow ShowPopup Uses a Conductor under the hood
38. Event Aggregator Communicate between objects in a loosely coupled way Follows a bus-style pub/sub model. Uses weak references Publishes on the UI thread.
40. Coroutines Wikipedia: “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.”
41. Coroutines Introduces asynchronous programming in a simple way. Build on top of iterators. 2 required actions Implement the IResult interface on some class, representing the task you wish to execute Yield instances of IResult from an Action
42. Coroutines Allows you to execute a method, pause it’s execution, do something else, come back and resume execution where you left off. Extremely powerful in task-based programming
47. Conclusions Caliburn.Micro is clean and simple Allows you to create very rich applications with a strong focus on maintainability and reuse A LOT of UI principles are applied in Caliburn.Micro Also check it’s big brother Caliburn “If you don’t like the code, use it as a learning tool” 47
Notes de l'éditeur
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