{"record":{"id":"7c28d86133f9293e","repo":"dotnet/wpf","slug":"sr-visual-nopresentationsource","errorCode":null,"errorMessage":"SR.Visual_NoPresentationSource","messagePattern":"SR\\.Visual_NoPresentationSource","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Media/Visual.cs","lineNumber":4723,"sourceCode":"                    dpi = new DpiScale(UIElement.DpiScaleXValues[actualIndex], UIElement.DpiScaleYValues[actualIndex]);\n                }\n            }\n            return dpi;\n        }\n\n        /// <summary>\n        /// This method converts a point in the current Visual's coordinate\n        /// system into a point in screen coordinates.\n        /// </summary>\n        public Point PointToScreen(Point point)\n        {\n            VerifyAPIReadOnly();\n\n            PresentationSource inputSource = PresentationSource.FromVisual(this);\n\n            if (inputSource == null)\n            {\n                throw new InvalidOperationException(SR.Visual_NoPresentationSource);\n            }\n\n            // Translate the point from the visual to the root.\n            GeneralTransform gUp = this.TransformToAncestor(inputSource.RootVisual);\n            if (gUp == null || !gUp.TryTransform(point, out point))\n            {\n                throw new InvalidOperationException(SR.Visual_CannotTransformPoint);\n            }\n\n            // Translate the point from the root to the screen\n            point = PointUtil.RootToClient(point, inputSource);\n            point = PointUtil.ClientToScreen(point, inputSource);\n\n            return point;\n        }\n\n        /// <summary>\n        /// This method converts a point in screen coordinates into a point","sourceCodeStart":4705,"sourceCodeEnd":4741,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Media/Visual.cs#L4705-L4741","documentation":"Visual.PointToScreen throws InvalidOperationException(SR.Visual_NoPresentationSource) when PresentationSource.FromVisual(this) returns null, meaning the visual is not yet connected to a presentation source (not rendered in a window/HwndSource). Point-to-screen conversion requires the visual to be live in a presented tree.","triggerScenarios":"Calling PointToScreen on a visual before it is loaded/shown, on an element in a non-presented tree, or on an element whose window was closed.","commonSituations":"Calling in a constructor instead of Loaded; detached elements created but never added to a window; popups/tooltips queried before opening.","solutions":["Call PointToScreen only after the element is loaded (subscribe to Loaded event)","Guard with PresentationSource.FromVisual(visual) != null before calling","Ensure the hosting Window is shown (IsLoaded / IsVisible) before converting coordinates"],"exampleFix":"// before\nctor: var screenPt = element.PointToScreen(new Point(0, 0));\n// after\nelement.Loaded += (s, e) =>\n{\n    if (PresentationSource.FromVisual(element) != null)\n        var screenPt = element.PointToScreen(new Point(0, 0));\n};","handlingStrategy":"validation","validationCode":"if (PresentationSource.FromVisual(visual) == null) return; // not yet presented","typeGuard":"bool IsPresented(Visual v) => PresentationSource.FromVisual(v) != null;","tryCatchPattern":"try { var p = visual.PointToScreen(point); } catch (InvalidOperationException) { /* visual not connected to a presentation source */ }","preventionTips":["Defer screen-coordinate work to the Loaded event","Check element.IsLoaded before PointToScreen","Guard with PresentationSource.FromVisual"],"tags":["wpf","visual-tree","coordinates","not-loaded"],"backgroundTag":"missing-presentation-source","analyzedSha":"81131a70a4c573cd62748a5c36908fc4d662daa9","analyzedAt":"2026-09-14T10:12:48.479Z","contentChangedAt":"2026-09-14T10:12:48.479Z","schemaVersion":2},"datasetVersion":"2026-09-21T21:30:21.729Z"}