如何给EventSetter中的Handler分配一个命令,我想这样写:
<Style x:Key="ItemStyle" TargetType="{x:Type ListBoxItem}">
<EventSetter Event="PreviewMouseDoubleClick" Handler="{Binding MyDoubleClickCommand}"/>
最佳答案
试试 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);
}
关于.net - 将命令分配给 EventSetter,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3924337/