I want to get notified when an item in a ListBox gets clicked by the mouse, whether it is already selected or not.
I searched and found this: (http://kevin-berridge.
There is another way to get MouseDown event in ListBox. You can add event handler for events that are marked as handled by using handledEventsToo
signature of AddHandler
method:
myListBox.AddHandler(UIElement.MouseDownEvent,
new MouseButtonEventHandler(ListBox_MouseDown), true);
Third parameter above is handledEventsToo
which ensures that this handler will be invoked no matter if it is already marked as Handled
(which ListBoxItem
does in ListBox).
See Marking Routed Events as Handled, and Class Handling for explanation.
See How to Attach to MouseDown Event on ListBox for example.