Silverlight Listbox fires MouseRightButtonDown, but not MouseLeftButtonDown

I have this problem in a larger project ... so I installed "Testpoject" as a proof of concept:

  • New Silverlight Application
  • Add List
  • Fill in the list with several flags
  • Register listBox1_MouseLeftButtonDown
  • register listBox1_MouseRightButtonDown

You will see that listBox1_MouseLeftButtonDown will not work under any circumstances .... listBox1_MouseRightButtonDown, however, works fine.

I tried using a custom class derived from a ListBox, and overriding it, assuming something in the ListBox class sets e.Handled = false, but that also did not change the behavior.

Any ideas on why this is happening and how to fix it?

(This problem also stops the parental control from receiving the Click-Event ... event, so the event transfer is interrupted)

: edit: I fixed my problem in a workaround ... so no answer is needed anymore. Just if someone wants to understand why this is happening for the sake of it;)

+3
source share
2 answers

This seems to answer your question. Quote:

This is because the ListBoxItem internally handles this event, as well as the MouseLeftButtonDown event (stop bubbling) to implement item selection.

The solution is to add an event handler to the code file. From the article:

, RoutedEventArgs Handled true , , , ! , AddHandler, Boolean handledEventsToo.

. , .

+5

. , , ListBoxItem Handled true.

, ListBoxItem.ItemTemplate .

<ListBox.ItemTemplate>
    <DataTemplate>
        <StackPanel Orientation="Horizontal" MouseLeftButtonDown="StackPanel_MouseLeftButtonDown">
        ... other controls ...
        </StackPanel>
    </DataTemplate>
</ListBox.ItemTemplate>
+1

Source: https://habr.com/ru/post/1744902/


All Articles