PrismLibrary/Prism · error · InvalidOperationException

ItemsControl's ItemsSource property is not empty. This…

Error message

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.

What it means

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.

Solutions

  1. Remove the ItemsSource assignment/binding from the control when using it as a region.
  2. Move data binding to a child control inside the region's views instead of the region host.
  3. Check for unintended inherited values of RegionManager.RegionName causing attachment to a bound control.
  4. Clear existing bindings (BindingOperations.ClearBinding) before region registration if set programmatically.

Example fix

<!-- before -->
<ListBox ItemsSource="{Binding MyItems}" prism:RegionManager.RegionName="MyRegion" />
<!-- after -->
<ListBox prism:RegionManager.RegionName="MyRegion" />
Defensive patterns

Strategy: validation

Validate before calling

if (itemsControl.ItemsSource is not null || itemsControl.HasBinding(ItemsControl.ItemsSourceProperty) is not null)
    throw new InvalidOperationException("Control used as region must not have ItemsSource set");

Type guard

bool CanHostRegion(ItemsControl c) => c.ItemsSource is null && c.HasBinding(ItemsControl.ItemsSourceProperty) is null;

Try / catch

try { regionManager.RegisterViewWithRegion("MyRegion", typeof(MyView)); }
catch (InvalidOperationException ex) when (ex.Message.Contains("ItemsSource")) { /* remove ItemsSource binding */ }

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Understand the failure class

Background: "Invalid state transition" errors: "status must be X, actually Y", "already rejected/charging/uninstalled", "cannot ... while running" — what they mean when a library rejects your call — this error's family across 31 libraries.

Related errors


AI-assisted analysis of PrismLibrary/Prism@358118cd64 (2026-09-15). Data as JSON: /api/errors/cb76cb332d4c80f8. Report an issue: GitHub.

Appendix: source

Thrown at src/Avalonia/Prism.Avalonia/Navigation/Regions/Behaviors/SelectorItemsSourceSyncBehavior.cs:75

            set
            {
                this.hostControl = value as Selector;
            }
        }

        /// <summary>
        /// Starts to monitor the <see cref="IRegion"/> to keep it in synch with the items of the <see cref="HostControl"/>.
        /// </summary>
        protected override void OnAttach()
        {
            bool itemsSourceIsSet = this.hostControl.ItemsSource != null;
            itemsSourceIsSet = itemsSourceIsSet || (hostControl.HasBinding(this.hostControl, ItemsControl.ItemsSourceProperty) != null);
            ////itemsSourceIsSet = itemsSourceIsSet || (BindingOperations.GetBinding(this.hostControl, ItemsControl.ItemsSourceProperty) != null);

            if (itemsSourceIsSet)
            {
                throw new InvalidOperationException(Resources.ItemsControlHasItemsSourceException);
            }

            this.SynchronizeItems();

            this.hostControl.SelectionChanged += this.HostControlSelectionChanged;
            this.Region.ActiveViews.CollectionChanged += this.ActiveViews_CollectionChanged;
            this.Region.Views.CollectionChanged += this.Views_CollectionChanged;
        }

        private void Views_CollectionChanged(object sender, NotifyCollectionChangedEventArgs e)
        {
            if (e.Action == NotifyCollectionChangedAction.Add)
            {
                int startIndex = e.NewStartingIndex;
                foreach (object newItem in e.NewItems)
                {
                    this.hostControl.Items.Insert(startIndex++, newItem);
                }

View on GitHub (pinned to 358118cd64)