diff --git a/src/Avalonia.Controls/ItemCollection.cs b/src/Avalonia.Controls/ItemCollection.cs index 4daea44d5e..c9265558f0 100644 --- a/src/Avalonia.Controls/ItemCollection.cs +++ b/src/Avalonia.Controls/ItemCollection.cs @@ -121,6 +121,10 @@ namespace Avalonia.Controls internal void SetItemsSource(IEnumerable? value) { + if (_mode != Mode.ItemsSource && Count > 0) + throw new InvalidOperationException( + "Items collection must be empty before using ItemsSource."); + _mode = value is not null ? Mode.ItemsSource : Mode.Items; SetSource(value ?? CreateDefaultCollection()); }