问题
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