How to catch the mouse to the left if the data template has a transparent background?

My DataTemplatelooks like this:

<DataTemplate x:Key="ItemTemplate">
<StackPanel MouseLeftButtonDown="StackPanel_MouseLeftButtonDown">

However, I can not catch the left mouse button. If I set the background of the template to some color, this is normal.

How to create transparent DataTemplateand catch an event MouseLefButtonDown?

Thanks.

+3
source share
2 answers

If you want to catch mouse events on the StackPanel itself, you just need to adjust the transparency of your brush:

<StackPanel MouseLeftButtonDown="StackPanel_MouseLeftButtonDown"
        Background="Transparent" Height="400" Width="400" >
<Button Content="dfsdf"/> 

+2
source

MouseLeftButtonDown . , , "" . , StackPanel, MouseLeftButtonDown, , , , StackPanel.

PreviewMouseLeftButtonDown, , . , , "" , . :

<StackPanel PreviewMouseLeftButtonDown="StackPanel_PreviewMouseLeftButtonDown">

, .

+1

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


All Articles