{"record":{"id":"41f02e62aadbf451","repo":"PrismLibrary/Prism","slug":"scrollview-s-content-property-is-not-empty-this-control-is","errorCode":null,"errorMessage":"ScrollView's Content property is not empty. \n    This control is being associated with a region, but the control is already bound to something else. \n    If you did not explicitly set the control's Content property, \n    this exception may be caused by a change in the value of the inherited RegionManager attached property.","messagePattern":"ScrollView's Content property is not empty\\. \n    This control is being associated with a region, but the control is already bound to something else\\. \n    If you did not explicitly set the control's Content property, \n    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/Maui/Prism.Maui/Navigation/Regions/Adapters/ScrollViewRegionAdapter.cs","lineNumber":35,"sourceCode":"        : base(regionBehaviorFactory)\n    {\n    }\n\n    /// <summary>\n    /// Adapts a <see cref=\"ScrollView\"/> to an <see cref=\"IRegion\"/>.\n    /// </summary>\n    /// <param name=\"region\">The new region being used.</param>\n    /// <param name=\"regionTarget\">The object to adapt.</param>\n    protected override void Adapt(IRegion region, ScrollView regionTarget)\n    {\n        ArgumentNullException.ThrowIfNull(region);\n        ArgumentNullException.ThrowIfNull(regionTarget);\n\n        // No binding check required as the ContentProperty is not Bindable\n        bool contentIsSet = regionTarget.Content != null;\n\n        if (contentIsSet)\n            throw new InvalidOperationException(Resources.ScrollViewHasContentException);\n\n        region.ActiveViews.CollectionChanged += delegate\n        {\n            regionTarget.Content = region.ActiveViews.FirstOrDefault() as View;\n        };\n\n        region.Views.CollectionChanged +=\n            (sender, e) =>\n            {\n                if (e.Action == NotifyCollectionChangedAction.Add && region.ActiveViews.Count() == 0)\n                {\n                    region.Activate(e.NewItems[0] as VisualElement);\n                }\n            };\n    }\n\n    /// <summary>\n    /// Creates a new instance of <see cref=\"Region\"/>.","sourceCodeStart":17,"sourceCodeEnd":53,"githubUrl":"https://github.com/PrismLibrary/Prism/blob/358118cd640d9a22ff8cf21c8ad197fa038b7990/src/Maui/Prism.Maui/Navigation/Regions/Adapters/ScrollViewRegionAdapter.cs#L17-L53","documentation":"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.","triggerScenarios":"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.","commonSituations":"<ScrollView RegionManager.RegionName=\"MyRegion\"><StackLayout>...</StackLayout></ScrollView> in XAML; setting Content programmatically then registering the region; dynamic RegionName changes on a populated ScrollView.","solutions":["Leave the ScrollView's Content empty and let the region populate it exclusively","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","Ensure nothing (code, styles, bindings) assigns Content before region registration","If you need active-view switching semantics, keep only the region binding and manage views through IRegion"],"exampleFix":"// before\n<ScrollView RegionManager.RegionName=\"MyRegion\">\n    <Label Text=\"Hello\" />\n</ScrollView>\n\n// after\n<ScrollView RegionManager.RegionName=\"MyRegion\" />","handlingStrategy":"validation","validationCode":"bool regionReady = scrollView is ScrollView sv && sv.Content is null;\nif (!regionReady) throw new InvalidOperationException(\"ScrollView must have null Content before registering as a region\");","typeGuard":"bool IsUsableAsRegion(ScrollView sv) => sv is not null && sv.Content is null;","tryCatchPattern":null,"preventionTips":["Never set Content on a ScrollView marked RegionManager.RegionName","Remove XAML children of region ScrollViews and let Prism populate Content","Check that no code-behind or style assigns Content before region registration"],"tags":["prism","maui","regions","xaml","invalid-state"],"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"}