Monday, July 12, 2010

WPF: Detect when someone double-clicks a listbox item

You can add a style to ListBox.ItemContainerStyle, and add an EventSetter there:

<listbox><br>    ....
    <listbox.itemcontainerstyle><br>        <style targettype="{x:Type ListBoxItem}" basedon="{StaticResource {x:Type ListBoxItem}}"><br />            <EventSetter Event="MouseDoubleClick" Handler="ListBoxItem_MouseDoubleClick"/><br />        </style>
    </listbox.itemcontainerstyle>
</listbox>
ListBoxItem_MouseDoubleClick is a method in your code behind with the correct signature forMouseDoubleClick.

No comments:

Post a Comment