WPF: Get MouseEnter Event When IsEnabled=false

谁都会走 提交于 2019-12-10 14:37:26

问题


I want to handle MouseEnter event for a Custom Control when control is disabled. Is there a way to handle it?


回答1:


The documentation for UIElement.IsEnabled documents the behaviour you see:

Elements that are not enabled do not participate in hit testing or focus and therefore will not be sources of input events.

The logical conclusion, to me, is that if you do want to handle mouse events, you don't disable the control. Instead, use some other method of achieving what you want. For example, if it's an input control, it may be good enough to make it read-only instead of disabled. Your question doesn't really explain why you want this, so I cannot guess what the right method for you will be.




回答2:


perhaps you could surround your custom control with a ContentControl (which must always be enabled) and handle MouseEnter event on the ContentControl.



来源:https://stackoverflow.com/questions/14187468/wpf-get-mouseenter-event-when-isenabled-false

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