MouseLeftButtonDown not recognized ListBox?

I ran into a huge problem, I tried everything I could, but I did not find any solution. I have a listBox with a DataTemplate. I want to use the MouseLeftButtonDown and MouseLeftButtonUp events to test the selected item, the same one the user clicked on.

The problem is that the MouseLeftButtonUp event is recognized, but not the MouseLeftButtonDown event.

Part of my XAML code:

<ListBox Grid.Row="1" MouseLeftButtonDown="listBox_Faits_MouseLeftButtonDown" MouseLeftButtonUp="listBox_Faits_MouseLeftButtonUp"> 

Code behind:

  private void listBox_Faits_MouseLeftButtonUp(object sender, MouseEventArgs e) { ... } private void listBox_Faits_MouseLeftButtonDown(object sender, MouseEventArgs e) { ... } 

Does anyone know why?

Thanks,

Hello,

Flo

+4
source share
1 answer

This is because the MouseLeftButtonDown event is handled by a list item. To process already processed events, you can subscribe to it in the code and indicate that you want to process processed events, for example:

 listBox_Faits.AddHandler(MouseLeftButtonDownEvent, new MouseButtonEventHandler(listBox_Faits_MouseLeftButtonDown), true); 
+11
source

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


All Articles