Skip to content

Commit ce016f7

Browse files
authored
handle re-entrant request to close ToolTip (#5013)
1 parent d14bf14 commit ce016f7

File tree

1 file changed

+39
-28
lines changed

1 file changed

+39
-28
lines changed

src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/PopupControlService.cs

Lines changed: 39 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -546,40 +546,51 @@ private void RaiseToolTipClosingEvent(bool reset)
546546
}
547547
finally
548548
{
549-
if (isOpen)
549+
// Raising an event calls out to app code, which
550+
// could cause a re-entrant call to this method that
551+
// sets _currentToopTip to null. If that happens,
552+
// there's no need to do the work again.
553+
if (_currentToolTip != null)
550554
{
551-
_currentToolTip.IsOpen = false;
552-
553-
// Setting IsOpen makes call outs to app code. So it is possible that
554-
// the _currentToolTip is deleted as a result of an action there. If that
555-
// were the case we do not need to set off the timer to close the tooltip.
556-
if (_currentToolTip != null)
555+
if (isOpen)
557556
{
558-
// Keep references and owner set for the fade out or slide animation
559-
// Owner is released when animation completes
560-
_forceCloseTimer = new DispatcherTimer(DispatcherPriority.Normal);
561-
_forceCloseTimer.Interval = Popup.AnimationDelayTime;
562-
_forceCloseTimer.Tick += new EventHandler(OnForceClose);
563-
_forceCloseTimer.Tag = _currentToolTip;
564-
_forceCloseTimer.Start();
557+
_currentToolTip.IsOpen = false;
558+
559+
// Setting IsOpen makes call outs to app code. So it is possible that
560+
// the _currentToolTip is nuked as a result of an action there. If that
561+
// were the case we do not need to set off the timer to close the tooltip.
562+
if (_currentToolTip != null)
563+
{
564+
// Keep references and owner set for the fade out or slide animation
565+
// Owner is released when animation completes
566+
_forceCloseTimer = new DispatcherTimer(DispatcherPriority.Normal);
567+
_forceCloseTimer.Interval = Popup.AnimationDelayTime;
568+
_forceCloseTimer.Tick += new EventHandler(OnForceClose);
569+
_forceCloseTimer.Tag = _currentToolTip;
570+
_forceCloseTimer.Start();
571+
}
572+
573+
_quickShow = true;
574+
ToolTipTimer = new DispatcherTimer(DispatcherPriority.Normal);
575+
ToolTipTimer.Interval = TimeSpan.FromMilliseconds(ToolTipService.GetBetweenShowDelay(o));
576+
ToolTipTimer.Tick += new EventHandler(OnBetweenShowDelay);
577+
ToolTipTimer.Start();
565578
}
579+
else
580+
{
581+
// Release owner now
582+
_currentToolTip.ClearValue(OwnerProperty);
566583

567-
_quickShow = true;
568-
ToolTipTimer = new DispatcherTimer(DispatcherPriority.Normal);
569-
ToolTipTimer.Interval = TimeSpan.FromMilliseconds(ToolTipService.GetBetweenShowDelay(o));
570-
ToolTipTimer.Tick += new EventHandler(OnBetweenShowDelay);
571-
ToolTipTimer.Start();
572-
}
573-
else
574-
{
575-
// Release owner now
576-
_currentToolTip.ClearValue(OwnerProperty);
584+
if (_ownToolTip)
585+
BindingOperations.ClearBinding(_currentToolTip, ToolTip.ContentProperty);
586+
}
577587

578-
if (_ownToolTip)
579-
BindingOperations.ClearBinding(_currentToolTip, ToolTip.ContentProperty);
588+
if (_currentToolTip != null)
589+
{
590+
_currentToolTip.FromKeyboard = false;
591+
_currentToolTip = null;
592+
}
580593
}
581-
_currentToolTip.FromKeyboard = false;
582-
_currentToolTip = null;
583594
}
584595
}
585596
}

0 commit comments

Comments
 (0)