How to assign a command to the Handler i开发者_JAVA百科n EventSetter, I want to to write this:
<Style x:Key="ItemStyle" TargetType="{x:Type ListBoxItem}">
<EventSetter Event="PreviewMouseDoubleClick" Handler="{Binding MyDoubleClickCommand}"/>
Try Marlon's Grech's attached commands behaviours, as mentioned in this previous question.
Alternatively, as a simpler but less flexible solution, provide a Handler
implementation in the code-behind to raise the command directly, like this:
<!-- In the XAML -->
<EventSetter Event="PreviewMouseDoubleClick" Handler="MyPreviewDoubleClickHandler"/>
// In the code-behind
private void MyPreviewDoubleClickHandler(object sender, RoutedEventArgs args) {
object my_param = ...;
MyCommand.Execute(my_param, this);
}
精彩评论