This relates to Eddie's answer.
I played around with it a bit and it is great I also created a little template for creating new commands. I'm using it with Sharpdevelop as a code snippet. Just paste the following into your code (e.g.via a snippet):
#region $nameCommand
public static readonly DependencyProperty $nameCommand =
EventBehaviourFactory.CreateCommandExecutionEventBehaviour(
Control.$nameEvent, "$nameCommand", typeof (ControlBehavior));
public static void Set$nameCommand(DependencyObject o, ICommand value)
{
o.SetValue($nameCommand, value);
}
public static ICommand Get$nameCommand(DependencyObject o)
{
return o.GetValue($nameCommand) as ICommand;
}
#endregion
Then do a search replace for "$name" with the name of the Event/Command e.g. MouseEnter
ote, it is importand, that you make sure you pick the right classname for the owner (in my case ControlBehavior.
I am attaching a class I created for common Mouse commands in the hopes that other people share as well and we don't just implement the same thing over and over, where we could have saved a lot of time by sharing. Here my complete ControlBehavior class (I did only implement the events that I needed so far):
public static class ControlBehavior
{
#region MouseEnterCommand
public static readonly DependencyProperty MouseEnterCommand =
EventBehaviourFactory.CreateCommandExecutionEventBehaviour(
Control.MouseEnterEvent, "MouseEnterCommand", typeof (ControlBehavior));
public static void SetMouseEnterCommand(DependencyObject o, ICommand value)
{
o.SetValue(MouseEnterCommand, value);
}
public static ICommand GetMouseEnterCommand(DependencyObject o)
{
return o.GetValue(MouseEnterCommand) as ICommand;
}
#endregion
#region MouseLeaveCommand
public static readonly DependencyProperty MouseLeaveCommand =
EventBehaviourFactory.CreateCommandExecutionEventBehaviour(
Control.MouseLeaveEvent, "MouseLeaveCommand", typeof (ControlBehavior));
public static void SetMouseLeaveCommand(DependencyObject o, ICommand value)
{
o.SetValue(MouseLeaveCommand, value);
}
public static ICommand GetMouseLeaveCommand(DependencyObject o)
{
return o.GetValue(MouseLeaveCommand) as ICommand;
}
#endregion
#region MouseDoubleClickCommand
public static readonly DependencyProperty MouseDoubleClickCommand =
EventBehaviourFactory.CreateCommandExecutionEventBehaviour(
Control.MouseDoubleClickEvent, "MouseDoubleClickCommand", typeof (ControlBehavior));
public static void SetMouseDoubleClickCommand(Control o, ICommand command)
{
o.SetValue(MouseDoubleClickCommand, command);
}
public static void GetMouseDoubleClickCommand(Control o)
{
o.GetValue(MouseDoubleClickCommand);
}
#endregion
#region MouseLeftButtonDownCommand
public static readonly DependencyProperty MouseLeftButtonDownCommand =
EventBehaviourFactory.CreateCommandExecutionEventBehaviour(
Control.MouseLeftButtonDownEvent, "MouseLeftButtonDownCommand", typeof (ControlBehavior));
public static void SetMouseLeftButtonDownCommand(DependencyObject o, ICommand value)
{
o.SetValue(MouseLeftButtonDownCommand, value);
}
public static ICommand GetMouseLeftButtonDownCommand(DependencyObject o)
{
return o.GetValue(MouseLeftButtonDownCommand) as ICommand;
}
#endregion
}
By using above template it took me only a few seconds for each command.