当控件被禁用时,我想为自定义控件处理 MouseEnter 事件.有没有办法处理它?
I want to handle MouseEnter event for a Custom Control when control is disabled. Is there a way to handle it?
UIElement.IsEnabled
记录了您看到的行为:
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.
这篇关于WPF:当 IsEnabled=false 时获取 MouseEnter 事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!