PrismLibrary/Prism · error · InvalidOperationException
Resources.ContentControlHasContentException
Error message
Resources.ContentControlHasContentException
What it means
ContentControlRegionAdapter.Adapt requires the target ContentControl's Content to be unset: if Content is non-null or has a binding on ContentControl.ContentProperty, it throws InvalidOperationException with Resources.ContentControlHasContentException. The region adapter must own the Content property to swap in the active view.
Solutions
- Clear the Content property/binding on the ContentControl and let the region manage content.
- Use a separate empty ContentControl as the region host and keep your bound control as a view inside the region.
- Move the previously-set content into a view registered with the region.
- Check for XAML child elements implicitly setting Content.
Example fix
// before
<ContentControl Content="{Binding Detail}" prism:RegionManager.RegionName="DetailRegion" />
// after
<ContentControl prism:RegionManager.RegionName="DetailRegion" /> Defensive patterns
Strategy: validation
Validate before calling
if (contentControl.Content != null || contentControl.HasBinding(ContentControl.ContentProperty))
throw new InvalidOperationException("ContentControl region host must have no Content set."); Type guard
bool IsRegionCompatible(ContentControl c) => c.Content == null && !c.HasBinding(ContentControl.ContentProperty);
Try / catch
try
{
RegionManager.SetRegionName(contentControl, "DetailRegion");
}
catch (InvalidOperationException ex) when (ex.Message.Contains("Content"))
{
logger.LogError(ex, "ContentControl already has Content; cannot be a region host.");
} Prevention
- Keep region-host ContentControls empty in XAML
- Move existing content into views registered with the region
- Remember child XAML elements implicitly set Content
When it happens
Trigger: Setting RegionManager.RegionName on a ContentControl whose Content is already set in XAML (e.g., <ContentControl Content="{Binding ...}" RegionName="..."/>) or assigned in code before region attachment.
Common situations: Adding RegionName to an existing content-bound control during MVVM refactors; implicit content from XAML child elements (the child becomes Content); design-time data left in the control at runtime.
Related errors
- Resources.ItemsControlHasItemsSourceException
- Resources.ItemsControlHasItemsSourceException
- ItemsControl's ItemsSource property is not empty. This…
- Resources.DeactiveNotPossibleException
- Resources.RegionCreationException
AI-assisted analysis of PrismLibrary/Prism@358118cd64 (2026-09-15).
Data as JSON: /api/errors/c73b503a41a8cb20.
Report an issue: GitHub.
Appendix: source
Thrown at src/Wpf/Prism.Wpf/Navigation/Regions/ContentControlRegionAdapter.cs:39
/// <summary>
/// Adapts a <see cref="ContentControl"/> 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, ContentControl regionTarget)
{
if (regionTarget == null)
throw new ArgumentNullException(nameof(regionTarget));
bool contentIsSet = regionTarget.Content != null;
#if !AVALONIA
contentIsSet = contentIsSet || regionTarget.HasBinding(ContentControl.ContentProperty);
#else
contentIsSet = contentIsSet || regionTarget[ContentControl.ContentProperty] != null;
#endif
if (contentIsSet)
throw new InvalidOperationException(Resources.ContentControlHasContentException);
region.ActiveViews.CollectionChanged += delegate
{
regionTarget.Content = region.ActiveViews.FirstOrDefault();
};
region.Views.CollectionChanged +=
(sender, e) =>
{
if (e.Action == NotifyCollectionChangedAction.Add && region.ActiveViews.Count() == 0)
{
region.Activate(e.NewItems[0]);
}
};
}
/// <summary>
/// Creates a new instance of <see cref="SingleActiveRegion"/>.View on GitHub (pinned to 358118cd64)