PrismLibrary/Prism · error · InvalidOperationException
Resources.ItemsControlHasItemsSourceException
Error message
Resources.ItemsControlHasItemsSourceException
What it means
ItemsControlRegionAdapter.Adapt throws InvalidOperationException with Resources.ItemsControlHasItemsSourceException when the target ItemsControl already has an ItemsSource or an ItemsSource binding. The region must control ItemsSource to reflect the region's views, so a pre-existing source conflicts.
Solutions
- Remove the ItemsSource binding/assignment and populate the region instead.
- Keep ItemsSource binding if you want plain data-binding — do not add RegionName to that control.
- Wrap the bound control in a view and register that view with the region.
- Verify no style or template sets ItemsSource (HasBinding detects it).
Example fix
// before
<ItemsControl ItemsSource="{Binding Rows}" prism:RegionManager.RegionName="RowsRegion" />
// after
<ItemsControl prism:RegionManager.RegionName="RowsRegion" /> Defensive patterns
Strategy: validation
Validate before calling
if (itemsControl.ItemsSource != null || itemsControl.HasBinding(ItemsControl.ItemsSourceProperty))
throw new InvalidOperationException("ItemsControl region host must not have ItemsSource set."); Type guard
bool IsRegionCompatible(ItemsControl c) => c.ItemsSource == null && !c.HasBinding(ItemsControl.ItemsSourceProperty);
Try / catch
try
{
RegionManager.SetRegionName(itemsControl, "RowsRegion");
}
catch (InvalidOperationException ex) when (ex.Message.Contains("ItemsSource"))
{
logger.LogError(ex, "ItemsControl has ItemsSource; cannot be a region host.");
} Prevention
- Choose one: ItemsSource data-binding or region population
- Search XAML for RegionName alongside ItemsSource during reviews
- Audit styles for ItemsSource setters
When it happens
Trigger: Applying RegionManager.RegionName to an ItemsControl/ListBox/ComboBox that already has ItemsSource bound or assigned in XAML/code.
Common situations: Converting a data-bound list into a region without removing the binding; template/style-set ItemsSource that developers forget about; mixing MVVM data-binding and Prism region population on the same control.
Related errors
- Resources.ItemsControlHasItemsSourceException
- Resources.ContentControlHasContentException
- 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/afe047f1d4c9c57a.
Report an issue: GitHub.
Appendix: source
Thrown at src/Wpf/Prism.Wpf/Navigation/Regions/ItemsControlRegionAdapter.cs:40
/// </summary>
/// <param name="region">The new region being used.</param>
/// <param name="regionTarget">The object to adapt.</param>
protected override void Adapt(IRegion region, ItemsControl regionTarget)
{
if (region == null)
throw new ArgumentNullException(nameof(region));
if (regionTarget == null)
throw new ArgumentNullException(nameof(regionTarget));
// NOTE: In Avalonia, regionTarget.ItemsSource will not be null. Keep it rollin' baby!
#if !AVALONIA
bool itemsSourceIsSet = regionTarget.ItemsSource != null;
itemsSourceIsSet = itemsSourceIsSet || regionTarget.HasBinding(ItemsControl.ItemsSourceProperty);
if (itemsSourceIsSet)
{
throw new InvalidOperationException(Resources.ItemsControlHasItemsSourceException);
}
// If control has child items, move them to the region and then bind control to region. Can't set ItemsSource if child items exist.
if (regionTarget.Items.Count > 0)
{
foreach (object childItem in regionTarget.Items)
{
region.Add(childItem);
}
// Control must be empty before setting ItemsSource
regionTarget.Items.Clear();
}
regionTarget.ItemsSource = region.Views;
#else
// If control has child items, move them to the region and then bind control to region. Can't set ItemsSource if child items exist.
if (regionTarget.ItemCount > 0)
{View on GitHub (pinned to 358118cd64)