{"record":{"id":"c73b503a41a8cb20","repo":"PrismLibrary/Prism","slug":"resources-contentcontrolhascontentexception","errorCode":null,"errorMessage":"Resources.ContentControlHasContentException","messagePattern":"Resources\\.ContentControlHasContentException","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"src/Wpf/Prism.Wpf/Navigation/Regions/ContentControlRegionAdapter.cs","lineNumber":39,"sourceCode":"        /// <summary>\n        /// Adapts a <see cref=\"ContentControl\"/> to an <see cref=\"IRegion\"/>.\n        /// </summary>\n        /// <param name=\"region\">The new region being used.</param>\n        /// <param name=\"regionTarget\">The object to adapt.</param>\n        protected override void Adapt(IRegion region, ContentControl regionTarget)\n        {\n            if (regionTarget == null)\n                throw new ArgumentNullException(nameof(regionTarget));\n\n            bool contentIsSet = regionTarget.Content != null;\n#if !AVALONIA\n            contentIsSet = contentIsSet || regionTarget.HasBinding(ContentControl.ContentProperty);\n#else\n            contentIsSet = contentIsSet || regionTarget[ContentControl.ContentProperty] != null;\n#endif\n\n            if (contentIsSet)\n                throw new InvalidOperationException(Resources.ContentControlHasContentException);\n\n            region.ActiveViews.CollectionChanged += delegate\n            {\n                regionTarget.Content = region.ActiveViews.FirstOrDefault();\n            };\n\n            region.Views.CollectionChanged +=\n                (sender, e) =>\n                {\n                    if (e.Action == NotifyCollectionChangedAction.Add && region.ActiveViews.Count() == 0)\n                    {\n                        region.Activate(e.NewItems[0]);\n                    }\n                };\n        }\n\n        /// <summary>\n        /// Creates a new instance of <see cref=\"SingleActiveRegion\"/>.","sourceCodeStart":21,"sourceCodeEnd":57,"githubUrl":"https://github.com/PrismLibrary/Prism/blob/358118cd640d9a22ff8cf21c8ad197fa038b7990/src/Wpf/Prism.Wpf/Navigation/Regions/ContentControlRegionAdapter.cs#L21-L57","documentation":"ContentControlRegionAdapter.Adapt requires the target ContentControl's Content to be unset: if Content is non-null or has a binding on ContentControl.ContentProperty, it throws InvalidOperationException with Resources.ContentControlHasContentException. The region adapter must own the Content property to swap in the active view.","triggerScenarios":"Setting RegionManager.RegionName on a ContentControl whose Content is already set in XAML (e.g., <ContentControl Content=\"{Binding ...}\" RegionName=\"...\"/>) or assigned in code before region attachment.","commonSituations":"Adding RegionName to an existing content-bound control during MVVM refactors; implicit content from XAML child elements (the child becomes Content); design-time data left in the control at runtime.","solutions":["Clear the Content property/binding on the ContentControl and let the region manage content.","Use a separate empty ContentControl as the region host and keep your bound control as a view inside the region.","Move the previously-set content into a view registered with the region.","Check for XAML child elements implicitly setting Content."],"exampleFix":"// before\n<ContentControl Content=\"{Binding Detail}\" prism:RegionManager.RegionName=\"DetailRegion\" />\n// after\n<ContentControl prism:RegionManager.RegionName=\"DetailRegion\" />","handlingStrategy":"validation","validationCode":"if (contentControl.Content != null || contentControl.HasBinding(ContentControl.ContentProperty))\n    throw new InvalidOperationException(\"ContentControl region host must have no Content set.\");","typeGuard":"bool IsRegionCompatible(ContentControl c) => c.Content == null && !c.HasBinding(ContentControl.ContentProperty);","tryCatchPattern":"try\n{\n    RegionManager.SetRegionName(contentControl, \"DetailRegion\");\n}\ncatch (InvalidOperationException ex) when (ex.Message.Contains(\"Content\"))\n{\n    logger.LogError(ex, \"ContentControl already has Content; cannot be a region host.\");\n}","preventionTips":["Keep region-host ContentControls empty in XAML","Move existing content into views registered with the region","Remember child XAML elements implicitly set Content"],"tags":["wpf","regions","content-control","conflict"],"backgroundTag":"mutually-exclusive-options","analyzedSha":"358118cd640d9a22ff8cf21c8ad197fa038b7990","analyzedAt":"2026-09-15T15:00:31.079Z","contentChangedAt":"2026-09-15T15:00:31.079Z","schemaVersion":2},"datasetVersion":"2026-09-16T04:17:20.429Z"}