当工具提示即将打开时,我希望在状态栏中显示wpf应用程序中任何控件的工具提示的文本。
当然,我可以尝试递归地遍历主窗口的所有子控件,并将它们的ToolTipOpening事件设置为始终相同的方法。但是有没有更简单的方法呢?
类似Application.Current.AnyToolTipOpening事件的东西?
发布于 2009-07-01 10:26:12
当然,试试这个:
EventManager.RegisterClassHandler(typeof(FrameworkElement), FrameworkElement.ToolTipOpeningEvent, new ToolTipEventHandler(ToolTipHandler));它为从FrameworkElement派生的所有类注册一个处理程序。
您的处理程序方法可能如下所示:
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
}
}发布于 2009-07-02 08:47:10
谢谢,这很管用。此外,要使状态栏文本在鼠标离开带有工具提示的控件时消失,请执行以下操作:
EventManager.RegisterClassHandler(typeof(FrameworkElement),
MouseLeaveEvent, new MouseEventHandler(ClearText));https://stackoverflow.com/questions/1067899
复制相似问题