Browse Source

Ensure Items are synchronised with Presenter.

Ensure that the `ItemsControl`'s presenter is notified of an `Items` change at the appropriate time.
Steven Kirk 6 years ago
parent
commit
496fae20e5

+ 6 - 1
src/Avalonia.Controls/ItemsControl.cs

@@ -356,10 +356,15 @@ namespace Avalonia.Controls
             var oldValue = e.OldValue as IEnumerable;
             var newValue = e.NewValue as IEnumerable;
 
-            Presenter?.ItemsChanged(new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Reset));
             UpdateItemCount();
             RemoveControlItemsFromLogicalChildren(oldValue);
             AddControlItemsToLogicalChildren(newValue);
+
+            if (Presenter != null)
+            {
+                Presenter.Items = newValue;
+            }
+
             SubscribeToItems(newValue);
         }
 

+ 3 - 0
src/Avalonia.Controls/Presenters/IItemsPresenter.cs

@@ -1,12 +1,15 @@
 // Copyright (c) The Avalonia Project. All rights reserved.
 // Licensed under the MIT license. See licence.md file in the project root for full license information.
 
+using System.Collections;
 using System.Collections.Specialized;
 
 namespace Avalonia.Controls.Presenters
 {
     public interface IItemsPresenter : IPresenter
     {
+        IEnumerable Items { get; set; }
+
         IPanel Panel { get; }
 
         void ItemsChanged(NotifyCollectionChangedEventArgs e);