{"record":{"id":"8b0f107481d2e9cf","repo":"dotnet/wpf","slug":"sr-documentgridvisualtreecontainsnondocumentgridpage","errorCode":null,"errorMessage":"SR.DocumentGridVisualTreeContainsNonDocumentGridPage","messagePattern":"SR\\.DocumentGridVisualTreeContainsNonDocumentGridPage","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/documents/DocumentGrid.cs","lineNumber":1062,"sourceCode":"\n                    if (background == null)\n                    {\n                        throw new InvalidOperationException(SR.DocumentGridVisualTreeContainsNonBorderAsFirstElement);\n                    }\n\n                    //We measure this to the size of our constraint.\n                    background.Measure(constraint);\n                }\n                //Otherwise it's a page.\n                else\n                {\n                    //Ensure that this is actually a DocumentGridPage.  If it is not,\n                    //Then someone's been mucking with our VisualTree, so we'll throw.\n                    DocumentGridPage page = _childrenCollection[i] as DocumentGridPage;\n\n                    if (page == null)\n                    {\n                        throw new InvalidOperationException(SR.DocumentGridVisualTreeContainsNonDocumentGridPage);\n                    }\n\n                    //Get the cached size of this page and scale it to our current scale factor.\n                    Size pageSize = _pageCache.GetPageSize(page.PageNumber);\n                    pageSize.Width *= Scale;\n                    pageSize.Height *= Scale;\n\n                    //Measure the page if necessary.\n                    if (!page.IsMeasureValid)\n                    {\n                        page.Measure(pageSize);\n\n                        //See if the cached size has changed since we Measured.\n                        //This can happen if in the course of Measuring the page\n                        //a GetPageAsync() calls back immediately with the real page size.\n                        //If this happens we need to re-measure the page before we finish here,\n                        //otherwise we'll end up with a page that's Measured to one size\n                        //and Arranged to another, which looks bad.","sourceCodeStart":1044,"sourceCodeEnd":1080,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/documents/DocumentGrid.cs#L1044-L1080","documentation":"InvalidOperationException from DocumentGrid.MeasureOverride: a child in the visual collection after the background is not a DocumentGridPage, meaning someone modified the internal visual tree. The throw guards the assumption that all measured pages are DocumentGrid pages.","triggerScenarios":"Thrown at src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/documents/DocumentGrid.cs:1062 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Avoid manipulating the DocumentGrid's visual children; use the documented paging APIs","If subclassing, restore the expected child types before the layout pass"],"exampleFix":null,"handlingStrategy":"validation","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"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"}