1
0
Эх сурвалжийг харах

Make ItemCount a direct property.

Fixes #2658
Steven Kirk 6 жил өмнө
parent
commit
336086a588

+ 12 - 2
src/Avalonia.Controls/ItemsControl.cs

@@ -36,6 +36,12 @@ namespace Avalonia.Controls
         public static readonly DirectProperty<ItemsControl, IEnumerable> ItemsProperty =
             AvaloniaProperty.RegisterDirect<ItemsControl, IEnumerable>(nameof(Items), o => o.Items, (o, v) => o.Items = v);
 
+        /// <summary>
+        /// Defines the <see cref="ItemCount"/> property.
+        /// </summary>
+        public static readonly DirectProperty<ItemsControl, int> ItemCountProperty =
+            AvaloniaProperty.RegisterDirect<ItemsControl, int>(nameof(ItemCount), o => o.ItemCount);
+
         /// <summary>
         /// Defines the <see cref="ItemsPanel"/> property.
         /// </summary>
@@ -55,6 +61,7 @@ namespace Avalonia.Controls
             AvaloniaProperty.Register<ItemsControl, IMemberSelector>(nameof(MemberSelector));
 
         private IEnumerable _items = new AvaloniaList<object>();
+        private int _itemCount;
         private IItemContainerGenerator _itemContainerGenerator;
         private IDisposable _itemsCollectionChangedSubscription;
 
@@ -110,10 +117,13 @@ namespace Avalonia.Controls
             set { SetAndRaise(ItemsProperty, ref _items, value); }
         }
 
+        /// <summary>
+        /// Gets the number of items in <see cref="Items"/>.
+        /// </summary>
         public int ItemCount
         {
-            get;
-            private set;
+            get => _itemCount;
+            private set => SetAndRaise(ItemCountProperty, ref _itemCount, value);
         }
 
         /// <summary>