WPF:不透明度和MouseEnter事件 [英] WPF: Opacity and the MouseEnter Event

查看:370
本文介绍了WPF:不透明度和MouseEnter事件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

作为图的一部分,我画了一些重叠的形状,每个不透明度= 0.5 ,喜欢这里:

As part of a diagram, I am drawing a few overlapping Shapes, each with Opacity=0.5, like here:

<Grid>
    <Rectangle Fill="Blue" Opacity="0.5" MouseEnter="Rectangle_MouseEnter" />
    <Rectangle Fill="Red" Opacity="0.5" />
</Grid>


private void Rectangle_MouseEnter(object sender, MouseEventArgs e)
  {
     MessageBox.Show("Entered");
  }

当用户输入用鼠标的形状,应显示一些附加信息,但该事件处理程序不会被调用。

When the user enters the shape with the mouse, some additional information should be displayed, but the event handler never gets called.

有没有办法让所有形状的MouseEnter事件,而不只是最上面?

Is there a way to get MouseEnter events for all Shapes, instead of just the topmost one?

推荐答案

通过您的布局只有最上面的矩形将提高MouseEnter事件。它完全覆盖第一矩形

With your layout only the topmost rectangle will raise MouseEnter event. It fully overlaps the first rectangle.

试用事件处理代码:

private void Rectangle_MouseEnter(object sender, MouseEventArgs e)
        {
            if (sender != grid.Children[0])
            {
                var rect = (grid.Children[0] as Rectangle);
                if (rect != null) rect.RaiseEvent(e);
            }
            else
            {
                MessageBox.Show("Entered.");
            }
        }

有关这个工程需要申请两个矩形到Rectangle_MouseEnter

For this works you need to subscribe both rectangles to Rectangle_MouseEnter.

这篇关于WPF:不透明度和MouseEnter事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆