Wpf Panel Background problem

狂风中的少年 提交于 2021-02-04 16:11:11

问题


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?


回答1:


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.



来源:https://stackoverflow.com/questions/1720444/wpf-panel-background-problem

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!