Caliburn.Micro: Jump Start Composite applications for  WPF, Silverlight, Win Phone Igor Moochnick Principal IgorShare Cons...
Brief History  <ul><li>Based on the mature Caliburn project </li></ul><ul><li>Created by Rob Eisenberg </li></ul><ul><li>G...
JumpStart your app <ul><li>Create a clean Silverlight solution (OOB no host)  </li></ul><ul><li>NuGet: Install-Package Cal...
Agenda <ul><li>Basic configuration and bootstrapping </li></ul><ul><li>Actions </li></ul><ul><li>Screens, Conductors and C...
Basic Configuration <ul><li>Convention over configuration </li></ul><ul><li>Bootstrapper executed at startup </li></ul><ul...
Actions - Basic <ul><li>Binding for methods </li></ul><ul><li>Leverages System.Windows.Interactivity for trigger mechanism...
Actions - Advanced <ul><li>Guard property </li></ul><ul><ul><li>Handler: “GetData” </li></ul></ul><ul><ul><li>Guard proper...
Actions - Snippets <ul><li>< Button   Content = &quot; Click Me &quot;  cal:Message.Attach = &quot; SayHello(Name) &quot; ...
Actions - Snippets <ul><li>< ItemsControl   x:Name = &quot; Items &quot; >   < ItemsControl.ItemTemplate > < DataTemplate ...
Fields and Properties <ul><li>Binding by convention </li></ul><ul><li>public   string  Description { get  {  return  _desc...
View Lifecycle <ul><li>Screen </li></ul><ul><ul><li>A stateful unit of work existing within the presentation tier of an ap...
Screen simple lifecycle <ul><li>ActivateItem is called for PageTwoViewModel </li></ul><ul><ul><li>OnInitialize  </li></ul>...
Conductors and Placeholders <ul><li>Conductors </li></ul><ul><ul><li>Conductor<T> </li></ul></ul><ul><ul><li>Conductor<T>....
Event Aggregator <ul><li>Loosely coupled communication pattern </li></ul><ul><li>Bus-style pub/sub model </li></ul><ul><li...
Coroutines <ul><li>Simplifies asynchronous development </li></ul><ul><li>Task-based programming </li></ul><ul><li>Long run...
Coroutines – how? <ul><li>Return IResult or an IEnumerable<IResult> from an action </li></ul><ul><li>Return a class that i...
Coroutines (simplified) Show “Progress” indicator Execute long running call Hide “Progress” indicator Build and navigate t...
Window Manager <ul><li>ShowDialog </li></ul><ul><li>ShowWindow </li></ul><ul><li>ShowPopup </li></ul>
Conventions <ul><li>Removes the need to write boiler plate code </li></ul><ul><li>Fully customizable </li></ul><ul><li>A l...
Conclusion <ul><li>Clean and simple </li></ul><ul><li>Simplifies the composition of the complex views </li></ul><ul><li>Re...
More information <ul><li>Caliburn.Micro documentation </li></ul><ul><li>http:// caliburnmicro.codeplex.com/documentation <...
Upcoming SlideShare
Loading in …5
×

Caliburn.micro jump start composite applications for WPF, Silverlight and WP7

5,486 views

Published on

Published in: Technology
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total views
5,486
On SlideShare
0
From Embeds
0
Number of Embeds
1,370
Actions
Shares
0
Downloads
0
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

Caliburn.micro jump start composite applications for WPF, Silverlight and WP7

  1. 1. Caliburn.Micro: Jump Start Composite applications for WPF, Silverlight, Win Phone Igor Moochnick Principal IgorShare Consulting [email_address] Blog: www.igorshare.com/blog
  2. 2. Brief History <ul><li>Based on the mature Caliburn project </li></ul><ul><li>Created by Rob Eisenberg </li></ul><ul><li>Grew from Rob’s MIX10 talk “Build Your Own MVVM Framework” </li></ul><ul><li>Around 2,000 lines of code </li></ul><ul><li>Made public July 2010 </li></ul><ul><li>Now the mainline </li></ul>
  3. 3. JumpStart your app <ul><li>Create a clean Silverlight solution (OOB no host) </li></ul><ul><li>NuGet: Install-Package Caliburn.Micro </li></ul><ul><li>Clean App.xaml.cs </li></ul><ul><li>Initialize bootstrapper </li></ul><ul><li>Run </li></ul>
  4. 4. Agenda <ul><li>Basic configuration and bootstrapping </li></ul><ul><li>Actions </li></ul><ul><li>Screens, Conductors and Composition </li></ul><ul><li>Event Aggregator </li></ul><ul><li>Coroutines </li></ul><ul><li>Window Manager </li></ul><ul><li>Conventions </li></ul>
  5. 5. Basic Configuration <ul><li>Convention over configuration </li></ul><ul><li>Bootstrapper executed at startup </li></ul><ul><li>Shell is initialized by the bootstrapper </li></ul><ul><li>Uses a pluggable model for IoC containers </li></ul><ul><li>Supports IoC of your choice (MEF, AutoFac, Unity, etc…) </li></ul>
  6. 6. Actions - Basic <ul><li>Binding for methods </li></ul><ul><li>Leverages System.Windows.Interactivity for trigger mechanism </li></ul><ul><ul><li>Use anything that inherits TriggerBase to trigger the sending of an action message (events, …) </li></ul></ul><ul><li>Allows </li></ul><ul><ul><li>Execution of the methods </li></ul></ul><ul><ul><li>Passing data from the UI into the methods </li></ul></ul><ul><ul><li>Synchronous/Asynchronous calls </li></ul></ul>
  7. 7. Actions - Advanced <ul><li>Guard property </li></ul><ul><ul><li>Handler: “GetData” </li></ul></ul><ul><ul><li>Guard property: “CanGetData” </li></ul></ul><ul><ul><li>Guard state change via INotifyPropertyChanged </li></ul></ul><ul><li>Attached actions </li></ul><ul><ul><li>cal:Message.Attach=&quot;Remove()“ </li></ul></ul><ul><li>Properties for actions </li></ul><ul><ul><li>$eventArgs </li></ul></ul><ul><ul><li>$dataContext </li></ul></ul><ul><ul><li>$source </li></ul></ul>
  8. 8. Actions - Snippets <ul><li>< Button Content = &quot; Click Me &quot; cal:Message.Attach = &quot; SayHello(Name) &quot; /> </li></ul><ul><li>< Button Content = &quot; Let's Talk &quot; cal:Message.Attach = &quot; [Event MouseEnter] = [Action Talk('Hello', Name.Text)]; [Event MouseLeave] = [Action Talk('Goodbye', Name.Text)] &quot; /> </li></ul>
  9. 9. Actions - Snippets <ul><li>< ItemsControl x:Name = &quot; Items &quot; > < ItemsControl.ItemTemplate > < DataTemplate > < StackPanel Orientation = &quot; Horizontal &quot; > < Button Content = &quot; Remove &quot; cal:Message.Attach = &quot; Remove($dataContext) &quot; /> < TextBlock Text = &quot; {Binding Id} &quot; /> </ StackPanel > </ DataTemplate > </ ItemsControl.ItemTemplate > </ ItemsControl > </li></ul>
  10. 10. Fields and Properties <ul><li>Binding by convention </li></ul><ul><li>public   string  Description { get  {  return  _description; } set  { _description =  value ; NotifyOfPropertyChange(() => Description); NotifyOfPropertyChange(() => CanSave); } } </li></ul>
  11. 11. View Lifecycle <ul><li>Screen </li></ul><ul><ul><li>A stateful unit of work existing within the presentation tier of an application </li></ul></ul><ul><ul><li>Has a lifecycle associated with it </li></ul></ul><ul><li>Screen Conductor </li></ul><ul><ul><li>Enforces the Screen Activation Lifecycle </li></ul></ul><ul><ul><li>Activates/Deactivates screens </li></ul></ul><ul><ul><li>Allows graceful shutdown </li></ul></ul><ul><li>Screen Collection </li></ul><ul><ul><li>Maintains the list of currently opened screens or documents </li></ul></ul>
  12. 12. Screen simple lifecycle <ul><li>ActivateItem is called for PageTwoViewModel </li></ul><ul><ul><li>OnInitialize </li></ul></ul><ul><ul><li>implements IViewAware? - OnViewLoaded </li></ul></ul><ul><li>Check PageOneViewModel: </li></ul><ul><ul><li>it implements IGuardClose? - CanClose </li></ul></ul><ul><ul><li>it implements IDeactivate? - OnDeactivate </li></ul></ul><ul><li>Check PageTwoViewModel: </li></ul><ul><ul><li>implements IChild<IConductor>? - hooks up the hierarchical relationship </li></ul></ul><ul><ul><li>implements IActivate? - OnActivate </li></ul></ul>
  13. 13. Conductors and Placeholders <ul><li>Conductors </li></ul><ul><ul><li>Conductor<T> </li></ul></ul><ul><ul><li>Conductor<T>.Collection.OneActive </li></ul></ul><ul><ul><li>Conductor<T>.Collection.AllActive </li></ul></ul><ul><li>Placeholders </li></ul><ul><ul><li>ContentControl </li></ul></ul><ul><ul><li>TransitioningContentControl </li></ul></ul><ul><ul><li>ItemsControl </li></ul></ul>
  14. 14. Event Aggregator <ul><li>Loosely coupled communication pattern </li></ul><ul><li>Bus-style pub/sub model </li></ul><ul><li>Weak references </li></ul><ul><li>Publishes on the UI thread </li></ul><ul><ul><li>IoC .Get< IEventAggregator >().Publish( new   Event () ) </li></ul></ul><ul><li>Handling </li></ul><ul><ul><li>IoC .Get< IEventAggregator >().Subscribe( this ); </li></ul></ul><ul><ul><li>IHandle < Event > </li></ul></ul>
  15. 15. Coroutines <ul><li>Simplifies asynchronous development </li></ul><ul><li>Task-based programming </li></ul><ul><li>Long running tasks </li></ul><ul><li>Multi-stage executions </li></ul>
  16. 16. Coroutines – how? <ul><li>Return IResult or an IEnumerable<IResult> from an action </li></ul><ul><li>Return a class that implements IResult </li></ul>
  17. 17. Coroutines (simplified) Show “Progress” indicator Execute long running call Hide “Progress” indicator Build and navigate to the new screen yield return yield return yield return yield return GetData()
  18. 18. Window Manager <ul><li>ShowDialog </li></ul><ul><li>ShowWindow </li></ul><ul><li>ShowPopup </li></ul>
  19. 19. Conventions <ul><li>Removes the need to write boiler plate code </li></ul><ul><li>Fully customizable </li></ul><ul><li>A lot of pre-defined default conventions </li></ul><ul><li>Conventions for </li></ul><ul><ul><li>View/ViewModel resolution </li></ul></ul><ul><ul><li>Data binding </li></ul></ul><ul><ul><li>Action binding </li></ul></ul>
  20. 20. Conclusion <ul><li>Clean and simple </li></ul><ul><li>Simplifies the composition of the complex views </li></ul><ul><li>Reduces the maintenance cost </li></ul><ul><li>Increases the reusability of the code and components - recomposition </li></ul>
  21. 21. More information <ul><li>Caliburn.Micro documentation </li></ul><ul><li>http:// caliburnmicro.codeplex.com/documentation </li></ul><ul><li>Caliburn documentation </li></ul><ul><li>http://caliburn.codeplex.com/documentation </li></ul>

×