如何在EventSetter中将命令分配给处理程序,我想写成:
<Style x:Key="ItemStyle" TargetType="{x:Type ListBoxItem}">
<EventSetter Event="PreviewMouseDoubleClick" Handler="{Binding MyDoubleClickCommand}"/> 发布于 2011-02-09 19:49:40
试试这个previous question.中提到的Marlon的Grech's attached commands behaviours
或者,作为一种更简单但灵活性较差的解决方案,可以在代码隐藏中提供一个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);
}https://stackoverflow.com/questions/3924337
复制相似问题