views:

278

answers:

2

In WPF, I get a tooltip to appear immediately like this:

TextBlock tb = new TextBlock();
tb.Text = name;
ToolTip tt = new ToolTip();
tt.Content = "This is some info on " + name + ".";
tb.ToolTip = tt;
tt.Cursor = Cursors.Help;
ToolTipService.SetInitialShowDelay(tb, 0);

This makes the user experience better since if the user wants to look at the tooltips of five items on the page, he doesn't have to wait that long second for each one.

But since Silverlight does not have SetInitialShowDelay, what is a workaround to make the tooltip appear immediately?

+2  A: 

You'll need to hook the MouseEnter event and show it straight away yourself:-

    TextBlock tb = new TextBlock(); 
    tb.Text = name; 
    ToolTip tt = new ToolTip(); 
    tt.Content = "This is some info on " + name + "."; 
    ToolTipService.SetToolTip(tb, tt);
    tb.MouseEnter += (s, args) => {  
      ((ToolTip)ToolTipService.GetToolTip((DependencyObject)s)).IsOpen = true;
    };
AnthonyWJones
that's a good start, it works in general, but sometimes leaves the tooltip on the screen as a ghost, and the first mouseenter seems to not work, only the second time, will work with this
Edward Tanguay
+1  A: 

Other than re-implementing the mouse enter (or the whole tooltip service), I'm afraid you might be out of luck - the delay you see is actually hard-coded into the "OnOwnerMouseEnter" method of the TooltipService:

(courtesy of Reflector)

    TimeSpan span = (TimeSpan) (DateTime.Now - _lastToolTipOpenedTime);
    if (TimeSpan.Compare(span, new TimeSpan(0, 0, 0, 0, 100)) <= 0)
    {
        OpenAutomaticToolTip(null, EventArgs.Empty);
    }
    else
    {
        if (_openTimer == null)
        {
            _openTimer = new DispatcherTimer();
            _openTimer.Tick += new EventHandler(ToolTipService.OpenAutomaticToolTip);
        }
        _openTimer.Interval = new TimeSpan(0, 0, 0, 0, 400);
        _openTimer.Start();
    }
JerKimball
It's ridiculous that this cannot be set with the normal methods available in WPF.
WmasterJ