Wpf面板后台问题
当我不设置面板背景时,我无法获取鼠标事件。为什么有这种行为? 我可以通过将背景设置为透明(默认情况下为空)来获取面板上的鼠标事件。 空背景和透明背景有什么区别?
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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
当
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 forBrushes.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-casingBrushes.Transparent
for this purpose.