I've implemented the attached command behavior pattern found here and it works well to allow e.g. a Border to have a left- or right-click event that fires in the ViewModel:
XAML:
<Border Background="Yellow" Width="350" Margin="0,0,10,0" Height="35" CornerRadius="2"
c:CommandBehavior.Event="MouseLeftButtonDown"
c:CommandBehavior.Command="{Binding PressedLeftButton}"
c:CommandBehavior.CommandParameter="MainBorder123">
<TextBlock Text="this is the click area"/>
</Border>
Code Behind:
public ICommand PressedLeftButton { get; private set; }
public MainViewModel()
{
Output = "original value";
PressedLeftButton = new SimpleCommand
{
ExecuteDelegate = parameterValue => {
Output = String.Format("left mouse button was pressed at {0} and sent the parameter value \"{1}\"", DateTime.Now.ToString(), parameterValue.ToString());
}
};
}
However, how do I attach two attached behaviors to one element, e.g. I want to do something like the following but it of course gives me an error:
<Border Background="Yellow" Width="350" Margin="0,0,10,0" Height="35" CornerRadius="2"
c:CommandBehavior.Event="MouseLeftButtonDown"
c:CommandBehavior.Command="{Binding PressedLeftButton}"
c:CommandBehavior.CommandParameter="MainBorder123"
c:CommandBehavior.Event="MouseRightButtonDown"
c:CommandBehavior.Command="{Binding PressedRighttButton}"
c:CommandBehavior.CommandParameter="MainBorder123"
>