如何在EventSetter中为Handler分配命令,我想写这个:
<Style x:Key="ItemStyle" TargetType="{x:Type ListBoxItem}">
<EventSetter Event="PreviewMouseDoubleClick" Handler="{Binding MyDoubleClickCommand}"/>
答案 0 :(得分:3)
尝试Marlon的Grech attached commands behaviours,如previous question.
中所述或者,作为一种更简单但不太灵活的解决方案,在代码隐藏中提供Handler
实现以直接引发命令,如下所示:
<!-- 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);
}