PrismLibrary/Prism · error · InvalidOperationException
Resources.LayoutViewHasChildrenException
Error message
Resources.LayoutViewHasChildrenException
What it means
LayoutRegionAdapter.Adapt throws when the target Layout already has children or a BindableLayout.ItemsSource set. The adapter drives the layout's children through BindableLayout.ItemsSource = region.Views, which cannot coexist with developer-supplied children or a bound items source.
Solutions
- Empty the layout (remove XAML children) and clear BindableLayout.ItemsSource before region registration.
- Or remove the region name and manage children normally if region behavior is not required.
- Add views through the region (region.Add / RequestNavigate) rather than declaring them inline.
Example fix
<!-- before -->
<StackLayout prism:RegionManager.RegionName="ItemsRegion">
<Label Text="Static" />
</StackLayout>
<!-- after -->
<StackLayout prism:RegionManager.RegionName="ItemsRegion" /> Defensive patterns
Strategy: validation
Validate before calling
bool regionOk = !(layout.Children?.Any() ?? false) && !layout.IsSet(BindableLayout.ItemsSourceProperty);
if (!regionOk) throw new InvalidOperationException("Clear children/BindableLayout.ItemsSource before using this layout as a region."); Try / catch
try { regionManager.RegisterRegions(); }
catch (InvalidOperationException ex) when (ex.Message.Contains("children"))
{
// empty the layout or remove the region name
} Prevention
- Keep region host layouts child-free in XAML.
- Do not set BindableLayout.ItemsSource on region hosts.
- Audit layouts for both static children and RegionName attributes.
When it happens
Trigger: Registering a region name on a StackLayout/Grid/FlexLayout that already declares XAML children (StackLayout with <Label/> etc.) or sets BindableLayout.ItemsSource in XAML/code.
Common situations: Adding prism:RegionManager.RegionName to an existing layout full of static controls; combining a bound layout with region registration while migrating from MVVM lists to Prism regions.
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
- Resources.CarouselViewHasItemsSourceException
- Resources.CollectionViewHasItemsSourceException
- Resources.ContentViewHasContentException
- region
- regionTarget
AI-assisted analysis of PrismLibrary/Prism@358118cd64 (2026-09-15).
Data as JSON: /api/errors/173208fe30f91058.
Report an issue: GitHub.
Appendix: source
Thrown at src/Maui/Prism.Maui/Navigation/Regions/Adapters/LayoutRegionAdapter.cs:37
/// <summary>
/// Adapts a <see cref="Layout"/> 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, Layout regionTarget)
{
if (region == null)
throw new ArgumentNullException(nameof(region));
if (regionTarget == null)
throw new ArgumentNullException(nameof(regionTarget));
bool itemsSourceIsSet = regionTarget.Children?.Any() ?? false || regionTarget.IsSet(BindableLayout.ItemsSourceProperty);
if (itemsSourceIsSet)
{
throw new InvalidOperationException(Resources.LayoutViewHasChildrenException);
}
BindableLayout.SetItemsSource(regionTarget, region.Views);
BindableLayout.SetItemTemplate(regionTarget, 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)