From ddacc112acfc482bb35498bb63a0ce38db797ca0 Mon Sep 17 00:00:00 2001 From: Steven Kirk Date: Wed, 8 Mar 2023 15:35:22 +0100 Subject: [PATCH] Throw if setting ItemsSource when Items present. --- src/Avalonia.Controls/ItemCollection.cs | 4 ++++ 1 file changed, 4 insertions(+) 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()); }