Tooltip reopened on unloaded controls

Topics: question
May 4, 2011 at 3:06 PM

Hi, I'm using Advanced ToolTips extensively in my current project.

Recently I've notice a bug that tooltip sometimes reopened on unloaded controls.

I take a look into the code and I think I found the problem.

I think we need to stop timer in UnregisterToolTip method for all tooltips.

I have added this code and it solves my problem.

            var toolTipTimer = toolTip.Timer;
            if (toolTipTimer != null && toolTipTimer.IsEnabled)
            {
                toolTipTimer.StopAndReset();
            }

The problem seems to be that timers still continue to work even when owner is unloaded, and this triggered CurrentToolTip to be shown.

May be you could apply this patch to your code or provide me with the better solution for my problem.

Also it seems to me that CurrentToolTip is never cleared. I think its also good to clear it when it's owner is unloaded.

Mar 23, 2012 at 2:14 AM

I had a problem using this as a validation error tooltip in grids where if the user hit esc to cancel the edit while the tooltip was still open, i think the control (textbox) which the tooltip was attached to went away, but the tooltip stayed open.  initialy i got an exception in GetTranslatedPoints() on this line:

try
{
generalTransform = frameworkElement.TransformToVisual(null);
}
catch (Exception ex)
{
//Debugger.Break();
return pointArray;
}

which i handled as you can see.  but the toooltip move to the top left corner and stayed open.  this is becuase in the returing method, PerformPlacement, the pointArray had data in it.  so in PerformPlacement() i determined if pointArray had no data, I then set the reference to the Tooltip, CurrentToolTip, to null.  Then the tooltip woud disapear and continue to re-appear. I found that if I stopped the time. all began to work correctly.  bellow is the code I added after returning to PerformPlacement:

// Before getting the exception...
var translatedPoints = GetTranslatedPoints((FrameworkElement)placementTarget);

// Returning back to PerformPlacement.  Test to see if no points have been set.  if not, then we handled the expetion and need to kill the tooltip.
if (translatedPoints.Length == 4 && translatedPoints[0] == new Point() && translatedPoints[1] == new Point() && translatedPoints[2] == new Point() && translatedPoints[3] == new Point())
{
    CurrentToolTip.Timer.StopAndReset();
    CurrentToolTip = null;
    return;
}

all is good now.