This serves as a quick guide to the most frequently used conventions and features in the Caliburn.Micro project.
This is automatically wiring events on controls to call methods on the ViewModel.
<Button x:Name="Save">
This will cause the Click event of the Button to call “Save” method on the ViewModel.
<Button cal:Message.Attach="Save">
This will again cause the “Click” event of the Button to call “Save” method on the ViewModel.
Different events can be used like this:
<Button cal:Message.Attach="[Event MouseEnter] = [Action Save]">
Different parameters can be passed to the method like this:
<Button cal:Message.Attach="[Event MouseEnter] = [Action Save($this)]">
<UserControl x:Class="Caliburn.Micro.CheatSheet.ShellView"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:i="clr-namespace:System.Windows.Interactivity;assembly=System.Windows.Interactivity"
xmlns:cal="http://www.caliburnproject.org">
<StackPanel>
<TextBox x:Name="Name" />
<Button Content="Save">
<i:Interaction.Triggers>
<i:EventTrigger EventName="Click">
<cal:ActionMessage MethodName="Save">
<cal:Parameter Value="{Binding ElementName=Name, Path=Text}" />
</cal:ActionMessage>
</i:EventTrigger>
</i:Interaction.Triggers>
</Button>
</StackPanel>
</UserControl>
This syntax is Expression Blend friendly.
This is automatically binding dependency properties on controls to properties on the ViewModel.
<TextBox x:Name="FirstName" />
Will cause the “Text” property of the TextBox to be bound to the “FirstName” property on the ViewModel.
<TextBox Text="{Binding Path=FirstName, Mode=TwoWay}" />
This is the normal way of binding properties.
The three different methods on the Event Aggregator are:
public interface IEventAggregator {
void Subscribe(object instance);
void Unsubscribe(object instance);
void Publish(object message, Action<System.Action> marshal);
}
An event can be a simple class such as:
public class MyEvent {
public MyEvent(string myData) {
this.MyData = myData;
}
public string MyData { get; private set; }
}