MouseLeftButtonUp and PreviewMouseLeftButtonUp not working on element when parent has a MouseLeftButtonDown event

41 Views Asked by At

I have a problem when I try to use MouseLeftButtonUp event handler on Image it's not working exactly when parent(For example Grid) has his own MouseLeftButtonDown event handler. However when I remove MouseLeftButtonUp from parent(For example Grid) MouseLeftButtonUp event handler on Image is working. So what should I do to ensure MouseLeftButtonUp event handler execution on Image as a parent of Grid that has his own MouseLeftButtonDown event handler? I hope someone will help. Thanks!

Xaml.cs code:

public void Exit_MouseLeftButtonUp(object sender, MouseButtonEventArgs e) => Application.Current.Shutdown();

Xaml code:

<Border Background="#7E2553" CornerRadius="20">
<Grid Background="#1D2B53"
      MouseLeftButtonDown="WindowPanel_MouseLeftButtonDown">

    <Image Width="48"
           Height="48"
           Margin="0,0,32,0"
           HorizontalAlignment="Right"
           VerticalAlignment="Center"
           Cursor="Hand"
           MouseLeftButtonUp="Exit_MouseLeftButtonUp">

        <Image.Source>

            <DrawingImage>
                <DrawingImage.Drawing>
                    <DrawingGroup ClipGeometry="M0,0 V300 H300 V0 H0 Z">
                        <DrawingGroup Opacity="1">
                            <DrawingGroup.ClipGeometry>
                                <RectangleGeometry RadiusX="0"
                                                   RadiusY="0"
                                                   Rect="0,0,300,300" />
                            </DrawingGroup.ClipGeometry>
                            <DrawingGroup Opacity="1">
                                <GeometryDrawing Brush="White" Geometry="F1 M300,300z M0,0z M244.802,61.643C234.168,50.875 224.661,42.297 210.837,35.523 202.151,31.261 191.669,34.934 187.47,43.717 183.243,52.501 186.889,63.072 195.566,67.334 205.86,72.375 212.776,77.95 220.72,85.992 259.717,125.427 259.717,189.586 220.72,229.011 201.83,248.125 176.694,258.624 149.984,258.624 123.266,258.624 98.138,248.116 79.247,229.011 40.251,189.586 40.251,125.427 79.247,85.992 87.218,77.941 95.099,72.384 104.885,67.352 113.15,63.081 116.608,52.519 112.597,43.726 108.584,34.952 99.952,31.341 91.482,35.487 78.051,42.082 65.844,50.875 55.184,61.643 2.901,114.498 2.901,200.488 55.184,253.352 81.33,279.775 115.662,293 149.994,293 184.334,293 218.666,279.784 244.803,253.352 297.104,200.506 297.104,114.507 244.802,61.643z M149.984,174C159.849,174,167.855,165.993,167.855,156.129L167.882,24.871C167.882,15.007 159.876,7 150.011,7 140.145,7 132.139,15.007 132.139,24.871L132.139,78.486 132.112,156.128C132.112,166.002,140.118,174,149.984,174z" />
                            </DrawingGroup>
                        </DrawingGroup>
                    </DrawingGroup>
                </DrawingImage.Drawing>
            </DrawingImage>

        </Image.Source>

    </Image>

</Grid>
</Border>

I tried MouseLeftButtonUp and PreviewMouseLeftButtonUp on Image - not working

However, other events like MouseLeftButtonDown works fine

0

There are 0 best solutions below