Avoiding visual is not connected to a presentationsource on Point.ToScreen wpf?

Viewed 3721

I am getting an exception Visual is not connected to presentation source in my wpf application when switching display monitors or rdc.

I am already checking the visibility before trying using Point.ToScreen. What else can i do to avoid the issue?What am i missing here.

"system.invalidoperationexception .This Visual is not connected to a PresentationSource"

if (_pinned && _parentControl != null && _parentControl.IsVisible &&
                (sender == null || !EventBlacklist.Contains(sender)))
            {
                Point location;

                try
                {
                    location = _parentControl.PointToScreen(new Point(0, 0));
                }
                catch
                {
                    return;
                }
}

Error Image

0 Answers
Related