There doesn't seem to be a .Show() kind of method for the Windows.Control.ToolTip, incl in ToolTipService.
When a Window is created at run-time using the Window object, it is not visible by default. To make it visible, we can use Show or ShowDialog method. Show method of Window class is responsible for displaying a window.
FindName method of FrameworkElement class is used to find elements or controls by their Name properties. This article shows how to find controls on a Window by name. FindName method of FrameworkElement class is used to find elements or controls by their Name properties.
What you need to do is make sure the ToolTip on the control is of type ToolTip. Then you can set the IsOpen property to true like so:
ToolTip tooltip = new ToolTip{ Content = "My Tooltip" }; NameTextBox.ToolTip = tooltip; tooltip.IsOpen = true;
If you would like to control how long the tooltip remains open, you can subscribe to the Opened
event and set a time delay before closing the tooltip.
Subscription has to be done before IsOpen = true
and it has to be an async method to avoid hanging up the UI.
var tooltip = new ToolTip { Content = "New tooltip text" }; MyControln.ToolTip = tooltip; tooltip.Opened += async delegate (object o, RoutedEventArgs args) { var s = o as ToolTip; // let the tooltip display for 1 second await Task.Delay(1000); s.IsOpen = false; // wait till the close tooltip animation finishes before changing to old tooltip text await Task.Delay(1000); s.Content = "Old tooltip text"; }; tooltip.IsOpen = true;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With