Wpf面板后台问题

发布于 2024-08-11 03:17:20 字数 87 浏览 5 评论 0原文

当我不设置面板背景时,我无法获取鼠标事件。为什么有这种行为? 我可以通过将背景设置为透明(默认情况下为空)来获取面板上的鼠标事件。 空背景和透明背景有什么区别?

When i don't set background of my panel i can not get mouse events on that. why this behaviour?
I am able to get mouse events on panel by setting Background to Transparent which is null by default.
Whats the difference between Background null and Transparent?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

野稚 2024-08-18 03:17:20

Background=null时,它在渲染时不会向MILCore发出任何绘图命令,并且在命中测试中不会计算控件的整个区域。

Background=Transparent时,它在渲染时向MILCore发出普通的绘图命令,并且它确实在命中测试中控制整个区域。

Brushes.Transparent 实际上是一个普通的画笔,其 alpha(不透明度)通道设置为零。因此,在大多数情况下它就像普通颜色一样。如果背景是普通颜色,则会检测到鼠标单击,因此 Brushes.Transparent 也会检测到鼠标单击。

也就是说,有一些地方代码会检测 Brushes.Transparent 并通过完全省略绘图命令来对其进行优化。例如,窗口透明度与操作系统的交互就会发生这种情况:操作系统不会获知任何用 Brushes.Transparent 绘制的区域都是应用程序的一部分,因此单击它不会执行任何操作。为此,这是通过特殊外壳 Brushes.Transparent 来完成的。

When Background=null it doesn't issue any drawing command to MILCore when rendering, and it doesn't count the control's entire area in hit testing.

When Background=Transparent, it issues an ordinary drawing command to MILCore when rendering, and it does control the entire area in hit testing.

Brushes.Transparent is really an ordinary brush with it's alpha (opacity) channel set to zero. Because of this, it acts like an ordinary color in most situations. If the background were an ordinary color, mouse clicks would be detected, so they are also detected for Brushes.Transparent.

That said, there are a few places where code detects Brushes.Transparent and optimizes it away by omitting a drawing command entirely. For example this happens for window transparency's interaction with the operatings system: The OS is not informed that any areas painted with Brushes.Transparent are part of the application, so clicking on it does nothing. This is done by special-casing Brushes.Transparent for this purpose.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文