{"record":{"id":"cb76cb332d4c80f8","repo":"PrismLibrary/Prism","slug":"itemscontrol-s-itemssource-property-is-not-empty-this","errorCode":null,"errorMessage":"ItemsControl's ItemsSource property is not empty. This control is being associated with a region, but the control is already bound to something else. If you did not explicitly set the control's ItemSource property, this exception may be caused by a change in the value of the inherited RegionManager attached property.","messagePattern":"ItemsControl's ItemsSource property is not empty\\. This control is being associated with a region, but the control is already bound to something else\\. If you did not explicitly set the control's ItemSource property, this exception may be caused by a change in the value of the inherited RegionManager attached property\\.","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"src/Avalonia/Prism.Avalonia/Navigation/Regions/Behaviors/SelectorItemsSourceSyncBehavior.cs","lineNumber":75,"sourceCode":"\n            set\n            {\n                this.hostControl = value as Selector;\n            }\n        }\n\n        /// <summary>\n        /// Starts to monitor the <see cref=\"IRegion\"/> to keep it in synch with the items of the <see cref=\"HostControl\"/>.\n        /// </summary>\n        protected override void OnAttach()\n        {\n            bool itemsSourceIsSet = this.hostControl.ItemsSource != null;\n            itemsSourceIsSet = itemsSourceIsSet || (hostControl.HasBinding(this.hostControl, ItemsControl.ItemsSourceProperty) != null);\n            ////itemsSourceIsSet = itemsSourceIsSet || (BindingOperations.GetBinding(this.hostControl, ItemsControl.ItemsSourceProperty) != null);\n\n            if (itemsSourceIsSet)\n            {\n                throw new InvalidOperationException(Resources.ItemsControlHasItemsSourceException);\n            }\n\n            this.SynchronizeItems();\n\n            this.hostControl.SelectionChanged += this.HostControlSelectionChanged;\n            this.Region.ActiveViews.CollectionChanged += this.ActiveViews_CollectionChanged;\n            this.Region.Views.CollectionChanged += this.Views_CollectionChanged;\n        }\n\n        private void Views_CollectionChanged(object sender, NotifyCollectionChangedEventArgs e)\n        {\n            if (e.Action == NotifyCollectionChangedAction.Add)\n            {\n                int startIndex = e.NewStartingIndex;\n                foreach (object newItem in e.NewItems)\n                {\n                    this.hostControl.Items.Insert(startIndex++, newItem);\n                }","sourceCodeStart":57,"sourceCodeEnd":93,"githubUrl":"https://github.com/PrismLibrary/Prism/blob/358118cd640d9a22ff8cf21c8ad197fa038b7990/src/Avalonia/Prism.Avalonia/Navigation/Regions/Behaviors/SelectorItemsSourceSyncBehavior.cs#L57-L93","documentation":"Prism's SelectorItemsSourceSyncBehavior attaches to a control's region and populates ItemsSource from the region's ActiveViews. It throws InvalidOperationException if the host control already has an ItemsSource set or a binding to ItemsControl.ItemsSourceProperty, because region sync would conflict with the existing source.","triggerScenarios":"Registering an ItemsControl/ListBox/ComboBox as a region (RegionManager.RegionName attached property) while the control also has ItemsSource set in XAML or code, or an ItemsSource binding declared, or the RegionManager.RegionName attached property value changing so the behavior attaches to a control already bound.","commonSituations":"Designer set ItemsSource in XAML and a developer later added RegionManager.RegionName to the same control; inherited RegionManager attached property value changed in the visual tree; migrating from manual collection binding to region-based navigation.","solutions":["Remove the ItemsSource assignment/binding from the control when using it as a region.","Move data binding to a child control inside the region's views instead of the region host.","Check for unintended inherited values of RegionManager.RegionName causing attachment to a bound control.","Clear existing bindings (BindingOperations.ClearBinding) before region registration if set programmatically."],"exampleFix":"<!-- before -->\n<ListBox ItemsSource=\"{Binding MyItems}\" prism:RegionManager.RegionName=\"MyRegion\" />\n<!-- after -->\n<ListBox prism:RegionManager.RegionName=\"MyRegion\" />","handlingStrategy":"validation","validationCode":"if (itemsControl.ItemsSource is not null || itemsControl.HasBinding(ItemsControl.ItemsSourceProperty) is not null)\n    throw new InvalidOperationException(\"Control used as region must not have ItemsSource set\");","typeGuard":"bool CanHostRegion(ItemsControl c) => c.ItemsSource is null && c.HasBinding(ItemsControl.ItemsSourceProperty) is null;","tryCatchPattern":"try { regionManager.RegisterViewWithRegion(\"MyRegion\", typeof(MyView)); }\ncatch (InvalidOperationException ex) when (ex.Message.Contains(\"ItemsSource\")) { /* remove ItemsSource binding */ }","preventionTips":["Never set ItemsSource on a control marked with RegionManager.RegionName","Search XAML for controls that combine both ItemsSource and RegionName","Bind data on views placed inside the region, not the region host"],"tags":["avalonia","regions","itemssource","conflict"],"backgroundTag":"invalid-state-transition","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"}