WPF:当 IsEnabled=false 时获取 MouseEnter 事件

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

本站部分内容来源互联网,如果有图片或者内容侵犯您的权益请联系我们删除!

相关文档推荐

DispatcherQueue null when trying to update Ui property in ViewModel(尝试更新ViewModel中的Ui属性时DispatcherQueue为空)
Drawing over all windows on multiple monitors(在多个监视器上绘制所有窗口)
Programmatically show the desktop(以编程方式显示桌面)
c# Generic Setlt;Tgt; implementation to access objects by type(按类型访问对象的C#泛型集实现)
InvalidOperationException When using Context Injection in ASP.Net Core(在ASP.NET核心中使用上下文注入时发生InvalidOperationException)
LINQ many-to-many relationship, how to write a correct WHERE clause?(LINQ多对多关系,如何写一个正确的WHERE子句?)