WPF flag control does not respond to MouseLeftButtonDown event

I have the following XAML code:

<Grid Background="Blue">
        <Grid MouseLeftButtonDown="Grid_MouseLeftButtonDown">
            <CheckBox MouseLeftButtonDown="CheckBox_MouseLeftButtonDown_1"></CheckBox>
        </Grid>
</Grid>

When I click the checkbox with the left mouse button, the declared event does not fire. Can anyone explain this behavior? thanks in advance

+3
source share
3 answers

The event is handled by something else (perhaps it is consumed by the event Checked).

If you change the event to PreviewMouseLeftButtonDown(tunnel version MouseLeftButtonDown), it will fire correctly.

+5
source

CheckBox ButtonBase, (OnMouseLeftButtonDown). UIElement.MouseLeftButtonDown ( ):

. , , . Mouse . , , . , .

ClickMode ClickMode.Hover, , , , . , , , , .

PreviewMouseLeftButtonDown. , , , , MouseDown - , , AddHandler .

+2

Franci ... MouseLeftDownEvent, clickMode = hover . MouseleftDownEvent, .

0

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


All Articles