WPF: Get MouseEnter Event When IsEnabled=false(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 事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:WPF:当 IsEnabled=false 时获取 MouseEnter 事件


- MoreLinq maxBy vs LINQ max + where 2022-01-01
- C#MongoDB使用Builders查找派生对象 2022-09-04
- 如何用自己压缩一个 IEnumerable 2022-01-01
- WebMatrix WebSecurity PasswordSalt 2022-01-01
- C# 中多线程网络服务器的模式 2022-01-01
- 带有服务/守护程序应用程序的 Microsoft Graph CSharp SDK 和 OneDrive for Business - 配额方面返回 null 2022-01-01
- 输入按键事件处理程序 2022-01-01
- Web Api 中的 Swagger .netcore 3.1,使用 swagger UI 设置日期时间格式 2022-01-01
- 在哪里可以找到使用中的C#/XML文档注释的好例子? 2022-01-01
- 良好实践:如何重用 .csproj 和 .sln 文件来为 CI 创建 2022-01-01