开发者

Assigning a command to the EventSetter

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);
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜