{"record":{"id":"41a98f2380dbde2b","repo":"dotnet/wpf","slug":"sr-framenoaddchild","errorCode":null,"errorMessage":"SR.FrameNoAddChild","messagePattern":"SR\\.FrameNoAddChild","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/Frame.cs","lineNumber":537,"sourceCode":"        //  Protected Methods\n        //\n        //------------------------------------------------------\n        #region Protected Methods\n\n        /// <summary>\n        /// Creates AutomationPeer (<see cref=\"UIElement.OnCreateAutomationPeer\"/>)\n        /// </summary>\n        protected override AutomationPeer OnCreateAutomationPeer()\n        {\n            return new FrameAutomationPeer(this);\n        }\n\n        /// <summary>\n        ///  Add an object child to this control\n        /// </summary>\n        protected override void AddChild(object value)\n        {\n            throw new InvalidOperationException(SR.FrameNoAddChild);\n        }\n\n        /// <summary>\n        ///  Add a text string to this control\n        /// </summary>\n        protected override void AddText(string text)\n        {\n            XamlSerializerUtil.ThrowIfNonWhiteSpaceInAddText(text, this);\n        }\n        #endregion\n\n        #region Event Handlers\n\n        private void _OnBPReady(Object o, BPReadyEventArgs e)\n        {\n            // update content property\n            SetCurrentValueInternal(ContentProperty, e.Content);\n","sourceCodeStart":519,"sourceCodeEnd":555,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/Frame.cs#L519-L555","documentation":"Frame overrides AddChild and unconditionally throws this InvalidOperationException: a Frame does not support object children. Navigation content is supplied through the Source property or Navigate(), not by adding child elements, so XAML child elements inside <Frame> are rejected.","triggerScenarios":"Declaring child elements directly inside <Frame>...</Frame> in XAML, or calling frame.AddChild(...) / AddText programmatically.","commonSituations":"Migrating markup from another ContentControl (e.g. swapping a ContentControl for a Frame but keeping inner elements); trying to embed static content in a Frame instead of using Source=\"page.xaml\" or Navigate.","solutions":["Set frame.Source = new Uri(\"Page1.xaml\", UriKind.Relative) instead of adding children.","Use frame.Navigate(pageOrUri) to display content.","If you only need static hosted content without navigation, use a ContentControl or similar container instead of Frame."],"exampleFix":"<!-- before: throws -->\n<Frame>\n  <TextBlock Text=\"hello\"/>\n</Frame>\n\n<!-- after -->\n<Frame Source=\"Page1.xaml\"/>\n<!-- or -->\n<ContentControl>\n  <TextBlock Text=\"hello\"/>\n</ContentControl>","handlingStrategy":"validation","validationCode":"// Never add children to Frame; set content via Source/Navigate.\nif (content is Uri uri) frame.Source = uri;\nelse frame.Navigate(content);","typeGuard":null,"tryCatchPattern":"try { frame.AddChild(value); }\ncatch (InvalidOperationException) { frame.Navigate(value); }","preventionTips":["Use Frame.Source or Frame.Navigate for content; never nest child elements in <Frame>.","Use ContentControl when static embedded content is what you need.","Grep XAML for inner elements inside Frame tags during migration from other containers."],"tags":["wpf","frame","navigation","unsupported-operation"],"backgroundTag":"unsupported-operation","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"}