PrismLibrary/Prism · error · InvalidOperationException

Resources.CollectionViewHasItemsSourceException

Error message

Resources.CollectionViewHasItemsSourceException

What it means

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.

Solutions

  1. Delete the ItemsSource assignment on the CollectionView that serves as a region.
  2. Or drop the region registration and keep the CollectionView as an ordinary data-bound list.
  3. Populate the region via region.Add / RequestNavigate instead of an observable collection binding.

Example fix

<!-- before -->
<CollectionView ItemsSource="{Binding Rows}"
                prism:RegionManager.RegionName="ListRegion" />

<!-- after -->
<CollectionView prism:RegionManager.RegionName="ListRegion" />
Defensive patterns

Strategy: validation

Validate before calling

bool regionOk = collectionView.ItemsSource is null && !collectionView.IsSet(ItemsView.ItemsSourceProperty);
if (!regionOk) throw new InvalidOperationException("Remove ItemsSource before using CollectionView as a region.");

Try / catch

try { regionManager.RegisterRegions(); }
catch (InvalidOperationException ex) when (ex.Message.Contains("ItemsSource"))
{
    // remove the binding or the region name
}

Prevention

When it happens

Trigger: Registering a region name on a CollectionView that also has ItemsSource="{Binding ...}" in XAML or collectionView.ItemsSource = ... in code.

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

Understand the failure class

Background: Conflicting config options: "cannot be used together" — configuration validation errors across open-source libraries — this error's family across 162 libraries.

Related errors


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

Appendix: source

Thrown at src/Maui/Prism.Maui/Navigation/Regions/Adapters/CollectionViewRegionAdapter.cs:34

        : base(regionBehaviorFactory)
    {
    }

    /// <summary>
    /// Adapts a <see cref="CollectionView"/> to an <see cref="IRegion"/>.
    /// </summary>
    /// <param name="region">The new region being used.</param>
    /// <param name="regionTarget">The object to adapt.</param>
    protected override void Adapt(IRegion region, CollectionView regionTarget)
    {
        ArgumentNullException.ThrowIfNull(region);
        ArgumentNullException.ThrowIfNull(regionTarget);

        bool itemsSourceIsSet = regionTarget.ItemsSource != null || regionTarget.IsSet(ItemsView.ItemsSourceProperty);

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

        regionTarget.ItemsSource = region.Views;
        regionTarget.ItemTemplate = new RegionItemsSourceTemplate();
    }

    /// <summary>
    /// Creates a new instance of <see cref="IRegion"/>.
    /// </summary>
    /// <returns>A new instance of <see cref="Region"/>.</returns>
    protected override IRegion CreateRegion(IContainerProvider container) =>
        container.Resolve<Region>();
}

View on GitHub (pinned to 358118cd64)