From 2c8ad03baeab72c4e74ec730ec90d5ed1562c053 Mon Sep 17 00:00:00 2001 From: David Stahl Date: Fri, 12 Jun 2020 12:30:54 -0400 Subject: [PATCH] Try to detect when the Visual isn't bound to a PresentationSource --- .../Position/ControlPositionProvider.cs | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/Src/ToastNotifications/Position/ControlPositionProvider.cs b/Src/ToastNotifications/Position/ControlPositionProvider.cs index 7d1b12d..d99f002 100644 --- a/Src/ToastNotifications/Position/ControlPositionProvider.cs +++ b/Src/ToastNotifications/Position/ControlPositionProvider.cs @@ -36,8 +36,21 @@ public Point GetPosition(double actualPopupWidth, double actualPopupHeight) if (source?.CompositionTarget == null) return new Point(0, 0); + var elementSource = PresentationSource.FromVisual(_element); + if (elementSource == null) + return new Point(0, 0); + Matrix transform = source.CompositionTarget.TransformFromDevice; - Point location = transform.Transform(_element.PointToScreen(new Point(0, 0))); + Point location; + + try + { + location = transform.Transform(_element.PointToScreen(new Point(0, 0))); + } + catch (InvalidOperationException) + { + return new Point(0, 0); + } switch (_corner) {