“拦截"打开任何工具提示应用程序 [英] "Intercept" the opening of any tooltip appwide
本文介绍了“拦截"打开任何工具提示应用程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
当工具提示即将打开时,我想在状态栏中显示我的 wpf 应用程序中任何控件的工具提示文本.
I want to show the text of a tooltip of any control in my wpf app inside a status bar, when a tooltip is about to be opened.
当然,我可以尝试递归遍历主窗口的所有子控件,然后将他们的 ToolTipOpening
事件设置为始终相同的方法.但是有没有更简单的方法?
Of course I could try to loop recursively through all child controls of the main window and
set their ToolTipOpening
event to always the same method. But is there an easier way ?
类似于 Application.Current.AnyToolTipOpening
事件?
推荐答案
当然,试试这个:
EventManager.RegisterClassHandler(typeof(FrameworkElement), FrameworkElement.ToolTipOpeningEvent, new ToolTipEventHandler(ToolTipHandler));
为从 FrameworkElement 派生的所有类注册一个处理程序.
That registers a handler for all classes that derive from FrameworkElement.
您的处理程序方法可能如下所示:
Your handler method might look like this:
private void ToolTipHandler(object sender, ToolTipEventArgs e) {
// To stop the tooltip from appearing, mark the event as handled
e.Handled = true;
FrameworkElement source = e.Source as FrameworkElement;
if (source != null) {
MessageBox.Show(source.ToolTip.ToString()); // or whatever you like
}
}
这篇关于“拦截"打开任何工具提示应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文