【问题标题】:How to click an object with Panel.ZIndex low than another in wpf?如何在 wpf 中单击 Panel.ZIndex 低于另一个对象的对象?
【发布时间】:2011-09-29 10:31:39
【问题描述】:

在 wpf 中,我必须单击具有 Panel.ZIndex="1" 的图像,但该图像“位于”另一个具有 Panel.ZIndex="2" 的图像的“下方”。事件 MouseDown 失败。该怎么做?

提前致谢, M.

<Grid >
    <Image Name="Image_1" 
           Panel.ZIndex="1" />

    <Image Name="Image_2" 
           Panel.ZIndex="2" />

</Grid>

【问题讨论】:

    标签: c# .net wpf c#-4.0


    【解决方案1】:

    尝试使用IsHitTestVisible

    <Grid >
       <Image Name="Image_1" 
              Panel.ZIndex="1" />
    
        <Image Name="Image_2" IsHitTestVisible="false" 
              Panel.ZIndex="2" />
    </Grid>
    

    【讨论】:

      【解决方案2】:

      您可以在所有其他图像之上放置一个透明图像,并在其上设置点击事件。

      【讨论】:

        【解决方案3】:

        唯一的方法是处理点击Image_2 并以编程方式点击Image_1。你不能破坏布局。

        或者,当然,更改ZIndex 属性。

        【讨论】:

          【解决方案4】:

          我想知道为什么鼠标事件不起作用? WPF 具有事件隧道模型,因此如果另一个元素没有使用 e.Handled = true 阻止它,您必须能够在任何元素上捕获鼠标事件...

          【讨论】:

            猜你喜欢
            • 1970-01-01
            • 1970-01-01
            • 2023-01-23
            • 2018-01-17
            • 1970-01-01
            • 1970-01-01
            • 2021-11-09
            • 2012-11-25
            • 1970-01-01
            相关资源
            最近更新 更多