{"record":{"id":"b747117ac67f33e0","repo":"PrismLibrary/Prism","slug":"layout-view-s-children-property-is-not-empty-this-control-is","errorCode":null,"errorMessage":"Layout<View>'s Children 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 Children or ItemsSource property, \n    this exception may be caused by a change in the value of the inherited RegionManager attached property.","messagePattern":"Layout<View>'s Children 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 Children or ItemsSource 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/LayoutViewRegionAdapter.cs","lineNumber":35,"sourceCode":"        : base(regionBehaviorFactory)\n    {\n    }\n\n    /// <summary>\n    /// Adapts a <see cref=\"Layout{View}\"/> 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, Layout<View> regionTarget)\n    {\n        ArgumentNullException.ThrowIfNull(region);\n        ArgumentNullException.ThrowIfNull(regionTarget);\n\n        bool itemsSourceIsSet = regionTarget.Children?.Any() ?? false || regionTarget.IsSet(BindableLayout.ItemsSourceProperty);\n\n        if (itemsSourceIsSet)\n        {\n            throw new InvalidOperationException(Resources.LayoutViewHasChildrenException);\n        }\n\n        BindableLayout.SetItemsSource(regionTarget, region.Views);\n        BindableLayout.SetItemTemplate(regionTarget, new RegionItemsSourceTemplate());\n    }\n\n    /// <summary>\n    /// Creates a new instance of <see cref=\"IRegion\"/>.\n    /// </summary>\n    /// <returns>A new instance of <see cref=\"Region\"/>.</returns>\n    protected override IRegion CreateRegion(IContainerProvider container) =>\n        container.Resolve<Region>();\n}\n","sourceCodeStart":17,"sourceCodeEnd":49,"githubUrl":"https://github.com/PrismLibrary/Prism/blob/358118cd640d9a22ff8cf21c8ad197fa038b7990/src/Maui/Prism.Maui/Navigation/Regions/Adapters/LayoutViewRegionAdapter.cs#L17-L49","documentation":"Prism.Maui's LayoutViewRegionAdapter binds a region's Views collection to a Layout via BindableLayout. Before adapting, it verifies the Layout does not already have Children or an ItemsSource set; if it does, the control is 'already bound to something else' and the adapter throws InvalidOperationException (Resources.LayoutViewHasChildrenException). This prevents two content sources from fighting over the same control.","triggerScenarios":"Calling RegionManager.RegisterRegions / region registration (via RegionManager.RegionName attached property) on a Layout (StackLayout, Grid, FlexLayout, etc.) that already has child views declared in XAML or code, or that has BindableLayout.ItemsSource set. Also occurs when the RegionManager.RegionName attached property value changes and re-adaptation is attempted on a populated layout.","commonSituations":"Declaring <StackLayout RegionManager.RegionName=\"MyRegion\"><Label .../></StackLayout> in XAML — the Label children trigger the throw. Setting ItemsSource on the same layout that is marked as a region. Migrating from Xamarin.Forms Prism where nested content was allowed.","solutions":["Remove all child elements and any BindableLayout.ItemsSource binding from the layout marked with RegionManager.RegionName; let Prism populate it exclusively","If you need static content plus region views, wrap the region layout inside another container (e.g. a Grid containing a label and an empty StackLayout region)","Verify no style or attached-property trigger is setting RegionManager.RegionName on a parent container that already has children","Check that RegionManager.RegionName is not being re-applied/dynamically changed on an already-populated layout"],"exampleFix":"// before\n<StackLayout RegionManager.RegionName=\"MyRegion\">\n    <Label Text=\"Header\" />\n</StackLayout>\n\n// after\n<StackLayout>\n    <Label Text=\"Header\" />\n    <StackLayout RegionManager.RegionName=\"MyRegion\" />\n</StackLayout>","handlingStrategy":"validation","validationCode":"bool regionReady = layout is Layout l && !l.Children.Any() && !l.IsSet(BindableLayout.ItemsSourceProperty);\nif (!regionReady) throw new InvalidOperationException($\"{layout.GetType().Name} must be empty before registering as a region\");","typeGuard":"bool IsUsableAsRegion(Layout layout) => layout is not null && !layout.Children.Any() && !layout.IsSet(BindableLayout.ItemsSourceProperty);","tryCatchPattern":null,"preventionTips":["Never declare child elements inside a XAML element marked RegionManager.RegionName","Keep BindableLayout.ItemsSource unset on region layouts","Wrap static content in a parent container and place an empty region layout alongside it"],"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"}