views:

222

answers:

1

I have this problem in a bigger Project...... so I set up a 'Testpoject' as Proof of Concept:

  • New Silverlight-Application
  • Add Listbox
  • Fill listbox with a few Checkboxes
  • Register listBox1_MouseLeftButtonDown
  • register listBox1_MouseRightButtonDown

You will see, that the listBox1_MouseLeftButtonDown won't fire under any circumstances.... listBox1_MouseRightButtonDown however fires just fine.

I tried using a custom Class deriving from ListBox and overriding, assuming something in the ListBox Class was setting e.Handled = false, but this did not change the behaviour, either.

Any Ideas on why this happens and how to fix?

(This problem also stops the 'parent'-control from receiving the Click-Event... so the Event-passing is broke)

:edit: I fixed my problem with a workaround... so an answer is not required anymore. Just if somebody feels like figuring out why this is happening for the sake of it ;)

+1  A: 

This seems to answer your question. To quote:

That's because ListBoxItem internally handles this event as well as the MouseLeftButtonDown event (halting the bubbling) to implement item selection.

The solution is to add the event handler in the code-behind file. From the article:

Although setting the RoutedEventArgs parameter's Handled property to true in a routed event handler appears to stop the tunneling or bubbling, individual handlers further up or down the tree can opt to receive the events anyway! This can only be done from procedural code, using an overload of AddHandler that adds a Boolean handledEventsToo parameter.

See the caveat at the end though.

Chry Cheng