{"record":{"id":"fc59810ff74e2979","repo":"PrismLibrary/Prism","slug":"resources-contentviewhascontentexception","errorCode":null,"errorMessage":"Resources.ContentViewHasContentException","messagePattern":"Resources\\.ContentViewHasContentException","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"src/Maui/Prism.Maui/Navigation/Regions/Adapters/ContentViewRegionAdapter{TContentView}.cs","lineNumber":35,"sourceCode":"    public ContentViewRegionAdapter(IRegionBehaviorFactory regionBehaviorFactory)\n        : base(regionBehaviorFactory)\n    {\n    }\n\n    /// <summary>\n    /// Adapts a <see cref=\"ContentView\"/> 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, TContentView regionTarget)\n    {\n        ArgumentNullException.ThrowIfNull(region);\n        ArgumentNullException.ThrowIfNull(regionTarget);\n\n        bool contentIsSet = regionTarget.Content != null || regionTarget.IsSet(ContentView.ContentProperty);\n\n        if (contentIsSet)\n            throw new InvalidOperationException(Resources.ContentViewHasContentException);\n\n        region.ActiveViews.CollectionChanged += delegate\n        {\n            regionTarget.Content = region.ActiveViews.FirstOrDefault() as View;\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] as VisualElement);\n                }\n            };\n    }\n\n    /// <summary>\n    /// Creates a new instance of <see cref=\"SingleActiveRegion\"/>.","sourceCodeStart":17,"sourceCodeEnd":53,"githubUrl":"https://github.com/PrismLibrary/Prism/blob/358118cd640d9a22ff8cf21c8ad197fa038b7990/src/Maui/Prism.Maui/Navigation/Regions/Adapters/ContentViewRegionAdapter{TContentView}.cs#L17-L53","documentation":"ContentViewRegionAdapter<TContentView>.Adapt throws when the target ContentView already has Content assigned (directly or via the BindableProperty). The adapter will set Content from region.ActiveViews, so pre-existing content conflicts with region-managed content.","triggerScenarios":"Marking a ContentView with prism:RegionManager.RegionName while it also declares child content in XAML (<ContentView>...views...</ContentView>) or sets Content in code.","commonSituations":"Adding a region name to a ContentView that already hosts static XAML content; template pages where a default placeholder content was left in place.","solutions":["Remove the XAML child content / Content assignment from the ContentView acting as a region.","Or remove the region name and keep the static content if region behavior is not needed.","Inject views into the region via IRegionManager instead of declaring them inline."],"exampleFix":"<!-- before -->\n<ContentView prism:RegionManager.RegionName=\"DetailRegion\">\n    <Label Text=\"Placeholder\" />\n</ContentView>\n\n<!-- after -->\n<ContentView prism:RegionManager.RegionName=\"DetailRegion\" />","handlingStrategy":"validation","validationCode":"bool regionOk = contentView.Content is null && !contentView.IsSet(ContentView.ContentProperty);\nif (!regionOk) throw new InvalidOperationException(\"Remove Content before using the ContentView as a region.\");","typeGuard":null,"tryCatchPattern":"try { regionManager.RegisterRegions(); }\ncatch (InvalidOperationException ex) when (ex.Message.Contains(\"Content\"))\n{\n    // clear XAML content or remove the region name\n}","preventionTips":["Keep region host ContentViews empty in XAML.","Do not leave placeholder children inside region hosts.","Add content through the region API only."],"tags":["regions","contentview","maui","content-conflict"],"backgroundTag":"conflicting-config-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"}