Skip to content

Commit b26e0cb

Browse files
committed
make popup position check a bit safer
1 parent 7c42dd3 commit b26e0cb

File tree

1 file changed

+12
-8
lines changed

1 file changed

+12
-8
lines changed

MaterialDesignThemes.Wpf/PopupBox.cs

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -423,14 +423,18 @@ protected override void OnMouseEnter(MouseEventArgs e)
423423
{
424424
//if the invisible popup that is watching the mouse, isn't where we expected it to be
425425
//then the main popup toggle has been moved off screen...so we shouldn't show the popup content
426-
var popupScreenPoint = _popupContentControl.PointToScreen(new Point());
427-
popupScreenPoint.Offset(-_popupContentControl.Margin.Left, -_popupContentControl.Margin.Top);
428-
var expectedPopupScreenPoint = PointToScreen(_popupPointFromLastRequest);
429-
430-
if (Math.Abs(popupScreenPoint.X - expectedPopupScreenPoint.X) > ActualWidth/3
431-
||
432-
Math.Abs(popupScreenPoint.Y - expectedPopupScreenPoint.Y) > ActualHeight/3)
433-
return;
426+
var inputSource = PresentationSource.FromVisual(_popupContentControl);
427+
if (inputSource != null)
428+
{
429+
var popupScreenPoint = _popupContentControl.PointToScreen(new Point());
430+
popupScreenPoint.Offset(-_popupContentControl.Margin.Left, -_popupContentControl.Margin.Top);
431+
var expectedPopupScreenPoint = PointToScreen(_popupPointFromLastRequest);
432+
433+
if (Math.Abs(popupScreenPoint.X - expectedPopupScreenPoint.X) > ActualWidth/3
434+
||
435+
Math.Abs(popupScreenPoint.Y - expectedPopupScreenPoint.Y) > ActualHeight/3)
436+
return;
437+
}
434438
}
435439

436440
SetCurrentValue(IsPopupOpenProperty, true);

0 commit comments

Comments
 (0)