WPF:当 IsEnabled=false 时获取 MouseEnter 事件 [英] WPF: Get MouseEnter Event When IsEnabled=false

查看:34
本文介绍了WPF:当 IsEnabled=false 时获取 MouseEnter 事件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当控件被禁用时,我想为自定义控件处理 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 事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆