开发者

Assigning a command to the EventSetter

开发者 https://www.devze.com 2023-01-20 06:42 出处:网络
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}\">

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

精彩评论

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

关注公众号