“Intercept” the opening of any tooltip throughout

I want to show the tooltip text of any control in my wpf application in the status bar when the tooltip is open.

Of course, I could try looping recursively through all the child controls of the main window and set ToolTipOpening always have the same method. But is there an easier way?

Something like the Application.Current.AnyToolTipOpening event?

+6
wpf tooltip
source share
2 answers

Of course, try the following:

 EventManager.RegisterClassHandler(typeof(FrameworkElement), FrameworkElement.ToolTipOpeningEvent, new ToolTipEventHandler(ToolTipHandler)); 

This registers a handler for all classes that are derived 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 } } 
+9
source share

Thanks, it worked. Also, so that the status bar text disappears when the mouse displays the control using a tooltip:

  EventManager.RegisterClassHandler(typeof(FrameworkElement), MouseLeaveEvent, new MouseEventHandler(ClearText)); 
+1
source share

All Articles