• Like
  • Save
MVVM with Caliburn.Micro
Upcoming SlideShare
Loading in...5

MVVM with Caliburn.Micro



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 ...

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.



Total Views
Views on SlideShare
Embed Views



2 Embeds 2

http://www.linkedin.com 1
https://www.linkedin.com 1



Upload Details

Uploaded via as Microsoft PowerPoint

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
Post Comment
Edit your comment
  • Include MainView.xaml
  • 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.
  • AllFriendsViewModel - PublishMainViewModel – ReceiveAppBootstrapper - Subscribe
  • MainViewModel - Edit
  • AllFriendsViewModel – ScreenMainViewModel – Conductor -Implement Handle ViewPersonMessage RefactoredViewPersonViewModel and EditPersonViewModel – Close

MVVM with Caliburn.Micro MVVM with Caliburn.Micro Presentation Transcript

  • MVVM with Caliburn.MicroBrent Edwards
  • Brent EdwardsLead Consultant with MagenicBrentE@magenic.com@brentledwardsbrentedwards.nethttps://github.com/brentedwards
  • Level Set – Audience Background• XAML (WPF, Silverlight, Windows Phone 7, WinRT)• MVVM• Caliburn.Micro
  • Sample Application - Phonebook[Demo]
  • What Is MVVM?• Model-View-ViewModel
  • 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
  • Bootstrapper[Demo]
  • Convention: Views/ViewModels• View Resolution is ViewModel-First• Views/ViewModels wired together by convention• Entity naming convention – {EntityName}ViewModel  {EntityName}View• Namespace naming convention (Good practice) – ProjectName.ViewModels.{ViewModel} – ProjectName.Views.{View}
  • ViewModel-First[Demo]
  • 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
  • Action Convention[Demo]
  • 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
  • Message.Attach[Demo]
  • More Message.Attach<Button Content="Remove" cal:Message.Attach="[Event Click] = [Action Remove($dataContext)]" /><Button Content="Click Me" cal:Message.Attach="[Event Click] = [Action SayHello(Name.Text)]" /><Button Content="Click Me" cal:Message.Attach="SayHello(Name)" /><Button Content="Lets Talk“ cal:Message.Attach="[Event MouseEnter] = [Action Talk(Hello, Name.Text)]; [Event MouseLeave] = [Action Talk(Goodbye, Name.Text)]" />
  • More Message.Attach• Other argument options – $eventArgs – $dataContext – $source – $view – $executionContext – $this
  • Event Aggregator• What is it? – Single source for communication across the application
  • Event Aggregator[Demo]
  • Window Manager• What is it? – It um… Manages Windows ;)• Use it to show a window, a dialog, or a popup
  • Window Manager[Demo]
  • 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
  • ViewModel Types[Demo]
  • Questions?
  • Brent EdwardsLead Consultant with MagenicBrentE@magenic.com@brentledwardsbrentedwards.nethttps://github.com/brentedwards