tags:

views:

3317

answers:

4

Hi,

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?

+2  A: 

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 the Opened event and then did this:

tooltip.IsOpen = (tooltip.Content != null);

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.

Daniel Earwicker
ToolTip has a property called HasContent which you could use instead
benPearce
+4  A: 

You probably want to use Popup instead of Tooltip, since Tooltip assumes that you're using it in the pre-defined UI-standards way.

I'm not sure why StaysOpen doesn't work, but ShowDuration works as documented in MSDN -- it's the amount of time the Tooltip is displayed WHEN it's displayed. Set it to a small amount (e.g. 500 msec) to see the difference.

The trick in your case is maintaining the "last hovered control" state, but once you have that it should be fairly trivial to change the placement target and the content dynamically (either manually, or via binding) if you're using one Popup, or hiding the last visible Popup if you're using multiple.

There are some gotchas with Popups as far as Window resizing and moving (Popups don't move w/the containers), so you may want to also have that in mind while you're tweaking the behavior. See this link for more details.

HTH.

micahtan
Also beware that Popups are always on top of all desktop objects - even if you switch to another program, the popup will be visible and obscure part of the other program.
Jeff B
A: 

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.

Carlo
+4  A: 

TooltipService.ShowsDuration works, but you must set it on the object having the Tooltip, like this:

<Label ToolTipService.ShowDuration="12000" Name="lblShowTooltip" Content="Shows tooltip">
    <Label.ToolTip>
        <ToolTip>
            <TextBlock>Hello world!</TextBlock>
        </ToolTip>
    </Label.ToolTip>
</Label>

I'd say that this design was chosen because it allows same tooltip with different timeouts on different controls.

Martin Konicek