Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/wpf/14.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 防止父级在子级鼠标向下移动时触发事件_C#_Wpf_Xaml - Fatal编程技术网

C# 防止父级在子级鼠标向下移动时触发事件

C# 防止父级在子级鼠标向下移动时触发事件,c#,wpf,xaml,C#,Wpf,Xaml,我在窗口的顶部放置了一个网格,其中有一个图像。网格可能正在拖动带有MouseDown事件的窗口 但是,每当我想对子图像触发MouseDown事件时,它都不起作用,而是触发网格的 private void toggleTbr_MouseLeftButtonDown(object sender, MouseButtonEventArgs e) { this.DragMove(); } private void leapTcb_MouseLeftButtonDown(object send

我在
窗口的顶部放置了一个
网格
,其中有一个
图像
网格
可能正在拖动带有
MouseDown
事件的窗口

但是,每当我想对
子图像触发
MouseDown
事件时,它都不起作用,而是触发
网格的

private void toggleTbr_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
{
     this.DragMove();
}

private void leapTcb_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
{
     e.Handled = true;
     //my code
}
如你所见,我尝试了
e.Handled=true
但是它没有改变任何东西,然后我想尝试使用
PreviewMouseLeftButtonDown
而不是
MouseLeftButtonDown
但是,还是一样

我在这里做错了什么,或者如何防止
网格
触发

XAML:


图像元素没有背景属性,而是直接在图像元素上设置源属性


然而,您使其运行,但通过指定的更改,它的行为与您想要的一样,至少在我的机器上。

使用此功能这是我这边的工作

<Grid x:Name="toggleTbr" MouseLeftButtonDown="toggleTbr_MouseLeftButtonDown" Background="Red">
        <Grid x:Name="leapTcb_" Height="21" Width="26">
<Image x:Name="leapTcb" PreviewMouseLeftButtonDown="leapTcb_MouseLeftButtonDown">
            <Image.Background>
                <ImageBrush Source="Resources/leap_1.png"/>
            </Image.Background>
        </Image>

        </Grid>
    </Grid>

您的代码工作正常,但如果不够,您可以尝试使用以下方法:

IsHitTestVisible="True"

哪个事件是从子映像引发的?@Sankarann
LeapTcb_MouseLeftButtonDown
@RajeevRanjan检查UpdateEyes,实际上我也做了更改以获得更好的性能。
IsHitTestVisible="True"