{"record":{"id":"3534f5ea75785686","repo":"dotnet/wpf","slug":"sr-panel-boundpanel-nochildren","errorCode":null,"errorMessage":"SR.Panel_BoundPanel_NoChildren","messagePattern":"SR\\.Panel_BoundPanel_NoChildren","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/UIElementCollection.cs","lineNumber":524,"sourceCode":"        {\n            get { return (_visualParent); }\n        }\n\n        // Helper function to validate element; will throw exceptions if problems are detected.\n        private void ValidateElement(UIElement element)\n        {\n            if (element == null)\n            {\n                throw new ArgumentNullException(SR.Format(SR.Panel_NoNullChildren, this.GetType()));\n            }\n        }\n\n        private void VerifyWriteAccess()\n        {\n            Panel p = _visualParent as Panel;\n            if (p != null && p.IsDataBound)\n            {\n                throw new InvalidOperationException(SR.Panel_BoundPanel_NoChildren);\n            }\n        }\n\n        internal FrameworkElement LogicalParent\n        {\n            get { return _logicalParent; }\n        }\n\n        private readonly VisualCollection _visualChildren;\n        private readonly UIElement _visualParent;\n        private readonly FrameworkElement _logicalParent;\n    }\n}\n","sourceCodeStart":506,"sourceCodeEnd":538,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/UIElementCollection.cs#L506-L538","documentation":"UIElementCollection.VerifyWriteAccess throws InvalidOperationException (Panel_BoundPanel_NoChildren) when a caller mutates the children of a Panel that is data-bound. A bound Panel generates its children from the binding, so manual Add/Remove/Clear/Insert would conflict with the generated content.","triggerScenarios":"Calling panel.Children.Add/Remove/Clear/Insert on a Panel whose IsDataBound is true — typically a Panel receiving content via ItemsSource-style data binding or x:Bind-style generated children.","commonSituations":"Developers take a panel that is the items host of a bound ItemsControl (or bind a panel's children) and then imperatively add controls to it at runtime.","solutions":["Remove the data binding and populate the panel's Children manually.","Or manipulate the underlying bound data collection (ObservableCollection) instead of panel.Children, letting the binding regenerate children.","Or place a separate, unbound container panel for manually-added elements."],"exampleFix":"// before\nboundPanel.Children.Add(new Button()); // throws\n// after\nitems.Add(new MyItem()); // modify bound source instead","handlingStrategy":"validation","validationCode":"if (panel is Panel p && p.IsDataBound) throw new InvalidOperationException(\"Panel is data-bound; modify the source collection instead.\");\npanel.Children.Add(child);","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Never mutate Children of an items-host or bound panel","Track which panels are data-bound in your app","Prefer ObservableCollection changes over direct child manipulation"],"tags":["wpf","data-binding","invalid-state"],"backgroundTag":"invalid-state-transition","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"}