With all the MVVM frameworks out there, it’s hard to know which one is best for you. In this session, we will look at one of the best MVVM frameworks out there: Caliburn.Micro. We will build an application from the ground up to show how to get started with Caliburn.Micro from the perspective that matters the most: the code.
Show Edit button XAML, how clicking it originally does nothing.Add Edit method to show convention
Add XAML for View method, then run and show exceptionThen add View method
$eventArgs – Passes the Trigger’s EventArgs or input parameter to your Action. Note: This will be null for guard methods since the trigger hasn’t actually occurred.$dataContext – Passes the DataContext of the element that the ActionMessage is attached to. This is very useful in Master/Detail scenarios where the ActionMessage may bubble to a parent VM but needs to carry with it the child instance to be acted upon.$source – The actual FrameworkElement that triggered the ActionMessage to be sent.$view - The view (usually a UserControl or Window) that is bound to the ViewModel.$executionContext - The actions's execution context, which contains all the above information and more. This is useful in advanced scenarios.$this - The actual ui element to which the action is attached.
What Is Caliburn.Micro?• Small, powerful MVVM framework for XAML platforms• Technologies Supported – WPF 4.0 – Silverlight 4.0/5.0 – WP7 – WinRT/Metro• http://caliburnmicro.codeplex.com/
How It Works• Some Configuration• Some Convention• Some Magic
Configuration: Bootstrapper• Application foundation• Configure Inversion of Control container• Bootstrapper<TRootModel> – Configures first View/ViewModel to show• By default, Nuget includes a Bootstrapper for MEF
Actions• What are they? – Call methods on ViewModel from event fired in View• 2 ways to use Actions 1. By Convention 2. Explicitly with Message.Attach
Actions - Convention• How it works – Name a Control in XAML – Create method on ViewModel with same name – Caliburn.Micro automagically wires them together • Remember the magic I mentioned?• Positives • Negatives – Very easy to develop – No runtime errors if names – Keeps XAML clean don’t match – No design-time support
Actions - Explicit• How it works – Add attached property Message.Attach – Specify the event, method to call, and even parameters• Positives • Negatives – No magic – None that I’ve found • Other devs can easily see what you are calling – Simple parsing gives great flexibility
ViewModel Types• Screen – Most basic ViewModel type – Implements basic ViewModely stuff • INotifyPropertyChanged• Conductor – Controls activation/deactivation of multi-Screen views – Has a collection of ViewModels to display