如何在EventSetter中给Handler分配一个命令,我想这样写:
<Style x:Key="ItemStyle" TargetType="{x:Type ListBoxItem}">
<EventSetter Event="PreviewMouseDoubleClick" Handler="{Binding MyDoubleClickCommand}"/>
如何在EventSetter中给Handler分配一个命令,我想这样写:
<Style x:Key="ItemStyle" TargetType="{x:Type ListBoxItem}">
<EventSetter Event="PreviewMouseDoubleClick" Handler="{Binding MyDoubleClickCommand}"/>
尝试 Marlon's Grech 的附加命令行为,如上一个问题中所述。
或者,作为一个更简单但不太灵活的解决方案,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);
}