I have a tooltip for a Label and I want it to stay open until the user moves the mouse to a different control.
I have tried the following properties on the tooltip:
StaysOpen="True"
and
TooltipService.ShowDuration = "60000"
But in both cases the tooltip is only displayed for exactly 5 seconds.
Why are these values being ignored?
I was wrestling with the WPF Tooltip only the other day. It doesn't seem to be possible to stop it from appearing and disappearing by itself, so in the end I resorted to handling the
Opened
event. For example, I wanted to stop it from opening unless it had some content, so I handled theOpened
event and then did this:It's a hack, but it worked.
Presumably you could similarly handle the
Closed
event and tell it to open again, thus keeping it visible.Just put this code in initialization section.
If you want to specify that only certain elements in your
Window
have effectively indefiniteToolTip
duration you can define aStyle
in yourWindow.Resources
for those elements. Here is aStyle
forButton
that has such aToolTip
:One can also add
Style.Resources
to theStyle
to change the appearance of theToolTip
it shows, for example:Note: When I did this I also used
BasedOn
in theStyle
so everything else defined for the version of my custom control with a normalToolTip
would be applied.Just for the sake of completeness: In code it looks like this:
Also if you ever want to put any other control in your ToolTip, it won't be focusable since a ToolTip itself can get focus. So Like micahtan said, your best shot is a Popup.
This was also driving me crazy tonight. I created a
ToolTip
subclass to handle the issue. For me, on .NET 4.0, theToolTip.StaysOpen
property is not "really" stays open.In the class below, use the new property
ToolTipEx.IsReallyOpen
, instead of propertyToolTip.IsOpen
. You will get the control you want. Via theDebug.Print()
call, you can watch in the debugger Output window just how many timesthis.IsOpen = false
is called! So much forStaysOpen
, or should I say"StaysOpen"
? Enjoy.Small rant: Why didn't Microsoft make
DependencyProperty
properties (getters/setters) virtual so we can accept/reject/adjust changes in subclasses? Or make avirtual OnXYZPropertyChanged
for each and everyDependencyProperty
? Ugh.---Edit---
My solution above looks weird in the XAML editor -- the tooltip is always showing, blocking some text in Visual Studio!
Here is a better way to solve this problem:
Some XAML:
Some code:
Conclusion: Something is different about classes
ToolTip
andContextMenu
. Both have "service" classes, likeToolTipService
andContextMenuService
, that manage certain properties, and both usePopup
as a "secret" parent control during display. Finally, I noticed ALL the XAML ToolTip examples on the Web do not use classToolTip
directly. Instead, they embed aStackPanel
withTextBlock
s. Things that make you say: "hmmm..."