PrismLibrary/Prism · error · InvalidOperationException

Resources.CarouselViewHasItemsSourceException

Error message

Resources.CarouselViewHasItemsSourceException

What it means

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.

Solutions

  1. Remove the ItemsSource binding/assignment from the CarouselView if it should be a region.
  2. If you need the bound data, keep it a normal CarouselView and do not register a region on it.
  3. Use the region approach exclusively: add views via IRegionManager.RequestNavigate or region.Add into region.Views.

Example fix

<!-- before -->
<CarouselView ItemsSource="{Binding Items}"
               prism:RegionManager.RegionName="CarouselRegion" />

<!-- after -->
<CarouselView prism:RegionManager.RegionName="CarouselRegion" />
Defensive patterns

Strategy: validation

Validate before calling

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

Try / catch

try { regionManager.RegisterRegions(); }
catch (InvalidOperationException ex) when (ex.Message.Contains("ItemsSource"))
{
    // unbind ItemsSource or drop the region registration
}

Prevention

When it happens

Trigger: Registering a region for a CarouselView in XAML (<prism:RegionManager.RegionName="MyRegion">) while also setting CarouselView.ItemsSource in XAML or code.

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

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/35814adc1182d4b4. Report an issue: GitHub.

Appendix: source

Thrown at src/Maui/Prism.Maui/Navigation/Regions/Adapters/CarouselViewRegionAdapter.cs:37

    public CarouselViewRegionAdapter(IRegionBehaviorFactory regionBehaviorFactory)
        : base(regionBehaviorFactory)
    {
    }

    /// <summary>
    /// Adapts a <see cref="CarouselView"/> 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, CarouselView regionTarget)
    {
        ArgumentNullException.ThrowIfNull(region);
        ArgumentNullException.ThrowIfNull(regionTarget);

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

        if (itemsSourceIsSet)
            throw new InvalidOperationException(Resources.CarouselViewHasItemsSourceException);


        regionTarget.ItemsSource = region.Views;
        regionTarget.ItemTemplate = new RegionItemsSourceTemplate();
        var regionBehavior = new CarouselRegionBehavior(region);
        regionTarget.Behaviors.Add(regionBehavior);

        region.ActiveViews.CollectionChanged += delegate
        {
            var activeView = region.ActiveViews.OfType<VisualElement>().FirstOrDefault();
            regionBehavior.CurrentView = activeView;
            regionTarget.CurrentItem = activeView;
        };

        void OnFirstItemAdded(object sender, NotifyCollectionChangedEventArgs e)
        {
            if (e.Action == NotifyCollectionChangedAction.Add)
            {

View on GitHub (pinned to 358118cd64)