{"record":{"id":"35814adc1182d4b4","repo":"PrismLibrary/Prism","slug":"resources-carouselviewhasitemssourceexception","errorCode":null,"errorMessage":"Resources.CarouselViewHasItemsSourceException","messagePattern":"Resources\\.CarouselViewHasItemsSourceException","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"src/Maui/Prism.Maui/Navigation/Regions/Adapters/CarouselViewRegionAdapter.cs","lineNumber":37,"sourceCode":"    public CarouselViewRegionAdapter(IRegionBehaviorFactory regionBehaviorFactory)\n        : base(regionBehaviorFactory)\n    {\n    }\n\n    /// <summary>\n    /// Adapts a <see cref=\"CarouselView\"/> 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, CarouselView 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            throw new InvalidOperationException(Resources.CarouselViewHasItemsSourceException);\n\n\n        regionTarget.ItemsSource = region.Views;\n        regionTarget.ItemTemplate = new RegionItemsSourceTemplate();\n        var regionBehavior = new CarouselRegionBehavior(region);\n        regionTarget.Behaviors.Add(regionBehavior);\n\n        region.ActiveViews.CollectionChanged += delegate\n        {\n            var activeView = region.ActiveViews.OfType<VisualElement>().FirstOrDefault();\n            regionBehavior.CurrentView = activeView;\n            regionTarget.CurrentItem = activeView;\n        };\n\n        void OnFirstItemAdded(object sender, NotifyCollectionChangedEventArgs e)\n        {\n            if (e.Action == NotifyCollectionChangedAction.Add)\n            {","sourceCodeStart":19,"sourceCodeEnd":55,"githubUrl":"https://github.com/PrismLibrary/Prism/blob/358118cd640d9a22ff8cf21c8ad197fa038b7990/src/Maui/Prism.Maui/Navigation/Regions/Adapters/CarouselViewRegionAdapter.cs#L19-L55","documentation":"CarouselViewRegionAdapter.Adapt refuses to adapt a region onto a CarouselView that already has an ItemsSource set (either assigned or a BindableProperty value set in XAML). The region adapter drives the CarouselView's items itself, so a developer-supplied ItemsSource would conflict with region view management.","triggerScenarios":"Registering a region for a CarouselView in XAML (<prism:RegionManager.RegionName=\"MyRegion\">) while also setting CarouselView.ItemsSource in XAML or code.","commonSituations":"Mixing data-binding with Prism regions - a developer data-binds the CarouselView and later adds a region name to it; copy-pasting a region name onto a CarouselView that was previously a plain bound list.","solutions":["Remove the ItemsSource binding/assignment from the CarouselView if it should be a region.","If you need the bound data, keep it a normal CarouselView and do not register a region on it.","Use the region approach exclusively: add views via IRegionManager.RequestNavigate or region.Add into region.Views."],"exampleFix":"<!-- before -->\n<CarouselView ItemsSource=\"{Binding Items}\"\n               prism:RegionManager.RegionName=\"CarouselRegion\" />\n\n<!-- after -->\n<CarouselView prism:RegionManager.RegionName=\"CarouselRegion\" />","handlingStrategy":"validation","validationCode":"bool regionOk = carousel.ItemsSource is null && !carousel.IsSet(ItemsView.ItemsSourceProperty);\nif (!regionOk) throw new InvalidOperationException(\"Remove ItemsSource before using CarouselView as a region.\");","typeGuard":null,"tryCatchPattern":"try { regionManager.RegisterRegions(); }\ncatch (InvalidOperationException ex) when (ex.Message.Contains(\"ItemsSource\"))\n{\n    // unbind ItemsSource or drop the region registration\n}","preventionTips":["Never set ItemsSource on a control registered as a region.","Audit XAML for controls having both RegionName and bindings.","Pick one pattern per control: data binding OR region."],"tags":["regions","carouselview","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"}