Browse Source

Throw if setting ItemsSource when Items present.

Steven Kirk 2 years ago
parent
commit
ddacc112ac
1 changed files with 4 additions and 0 deletions
  1. 4 0
      src/Avalonia.Controls/ItemCollection.cs

+ 4 - 0
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());
         }