{"record":{"id":"04bd74b003454cbf","repo":"PrismLibrary/Prism","slug":"resources-collectionviewhasitemssourceexception","errorCode":null,"errorMessage":"Resources.CollectionViewHasItemsSourceException","messagePattern":"Resources\\.CollectionViewHasItemsSourceException","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"src/Maui/Prism.Maui/Navigation/Regions/Adapters/CollectionViewRegionAdapter.cs","lineNumber":34,"sourceCode":"        : base(regionBehaviorFactory)\n    {\n    }\n\n    /// <summary>\n    /// Adapts a <see cref=\"CollectionView\"/> 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, CollectionView regionTarget)\n    {\n        ArgumentNullException.ThrowIfNull(region);\n        ArgumentNullException.ThrowIfNull(regionTarget);\n\n        bool itemsSourceIsSet = regionTarget.ItemsSource != null || regionTarget.IsSet(ItemsView.ItemsSourceProperty);\n\n        if (itemsSourceIsSet)\n        {\n            throw new InvalidOperationException(Resources.CollectionViewHasItemsSourceException);\n        }\n\n        regionTarget.ItemsSource = region.Views;\n        regionTarget.ItemTemplate = new RegionItemsSourceTemplate();\n    }\n\n    /// <summary>\n    /// Creates a new instance of <see cref=\"IRegion\"/>.\n    /// </summary>\n    /// <returns>A new instance of <see cref=\"Region\"/>.</returns>\n    protected override IRegion CreateRegion(IContainerProvider container) =>\n        container.Resolve<Region>();\n}\n","sourceCodeStart":16,"sourceCodeEnd":48,"githubUrl":"https://github.com/PrismLibrary/Prism/blob/358118cd640d9a22ff8cf21c8ad197fa038b7990/src/Maui/Prism.Maui/Navigation/Regions/Adapters/CollectionViewRegionAdapter.cs#L16-L48","documentation":"CollectionViewRegionAdapter.Adapt throws when the target CollectionView already has an ItemsSource (set directly or via BindableProperty). The adapter must own ItemsSource (bound to region.Views) and an ItemTemplate, so a pre-set ItemsSource is treated as a conflict and rejected.","triggerScenarios":"Registering a region name on a CollectionView that also has ItemsSource=\"{Binding ...}\" in XAML or collectionView.ItemsSource = ... in code.","commonSituations":"Converting an existing data-bound CollectionView into a Prism region without removing its binding; leaving both region registration and a ViewModel collection binding on the same control.","solutions":["Delete the ItemsSource assignment on the CollectionView that serves as a region.","Or drop the region registration and keep the CollectionView as an ordinary data-bound list.","Populate the region via region.Add / RequestNavigate instead of an observable collection binding."],"exampleFix":"<!-- before -->\n<CollectionView ItemsSource=\"{Binding Rows}\"\n                prism:RegionManager.RegionName=\"ListRegion\" />\n\n<!-- after -->\n<CollectionView prism:RegionManager.RegionName=\"ListRegion\" />","handlingStrategy":"validation","validationCode":"bool regionOk = collectionView.ItemsSource is null && !collectionView.IsSet(ItemsView.ItemsSourceProperty);\nif (!regionOk) throw new InvalidOperationException(\"Remove ItemsSource before using CollectionView as a region.\");","typeGuard":null,"tryCatchPattern":"try { regionManager.RegisterRegions(); }\ncatch (InvalidOperationException ex) when (ex.Message.Contains(\"ItemsSource\"))\n{\n    // remove the binding or the region name\n}","preventionTips":["Remove ItemsSource bindings when registering a CollectionView region.","Grep XAML for RegionManager.RegionName controls that also bind ItemsSource.","Populate regions via RequestNavigate, not bindings."],"tags":["regions","collectionview","maui","itemssource-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"}