PrismLibrary/Prism · error · InvalidOperationException

ScrollView's Content property is not empty. This…

Error message

ScrollView's Content 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 Content property, 
    this exception may be caused by a change in the value of the inherited RegionManager attached property.

What it means

ScrollViewRegionAdapter adapts a ScrollView to a region by setting its Content from the region's ActiveViews. Before adapting, it checks that ScrollView.Content is null; if Content is already set the adapter throws InvalidOperationException (Resources.ScrollViewHasContentException) because the existing content would conflict with region-managed content.

Solutions

  1. Leave the ScrollView's Content empty and let the region populate it exclusively
  2. Move existing content out — e.g. put the ScrollView as a child container and mark an empty inner region, or wrap existing content outside the region
  3. Ensure nothing (code, styles, bindings) assigns Content before region registration
  4. If you need active-view switching semantics, keep only the region binding and manage views through IRegion

Example fix

// before
<ScrollView RegionManager.RegionName="MyRegion">
    <Label Text="Hello" />
</ScrollView>

// after
<ScrollView RegionManager.RegionName="MyRegion" />
Defensive patterns

Strategy: validation

Validate before calling

bool regionReady = scrollView is ScrollView sv && sv.Content is null;
if (!regionReady) throw new InvalidOperationException("ScrollView must have null Content before registering as a region");

Type guard

bool IsUsableAsRegion(ScrollView sv) => sv is not null && sv.Content is null;

Prevention

When it happens

Trigger: Marking a ScrollView with RegionManager.RegionName when it already declares a Content child in XAML or code, or when Content was assigned before region registration. Re-triggered if the RegionManager.RegionName attached property changes on a ScrollView that has content.

Common situations: <ScrollView RegionManager.RegionName="MyRegion"><StackLayout>...</StackLayout></ScrollView> in XAML; setting Content programmatically then registering the region; dynamic RegionName changes on a populated ScrollView.

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/41f02e62aadbf451. Report an issue: GitHub.

Appendix: source

Thrown at src/Maui/Prism.Maui/Navigation/Regions/Adapters/ScrollViewRegionAdapter.cs:35

        : base(regionBehaviorFactory)
    {
    }

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

        // No binding check required as the ContentProperty is not Bindable
        bool contentIsSet = regionTarget.Content != null;

        if (contentIsSet)
            throw new InvalidOperationException(Resources.ScrollViewHasContentException);

        region.ActiveViews.CollectionChanged += delegate
        {
            regionTarget.Content = region.ActiveViews.FirstOrDefault() as View;
        };

        region.Views.CollectionChanged +=
            (sender, e) =>
            {
                if (e.Action == NotifyCollectionChangedAction.Add && region.ActiveViews.Count() == 0)
                {
                    region.Activate(e.NewItems[0] as VisualElement);
                }
            };
    }

    /// <summary>
    /// Creates a new instance of <see cref="Region"/>.

View on GitHub (pinned to 358118cd64)