diff --git a/Toolkit.Foundation/ObservableCollection.cs b/Toolkit.Foundation/ObservableCollection.cs index 69bbe08..74df0f9 100644 --- a/Toolkit.Foundation/ObservableCollection.cs +++ b/Toolkit.Foundation/ObservableCollection.cs @@ -37,17 +37,22 @@ public partial class ObservableCollection : private readonly System.Collections.ObjectModel.ObservableCollection collection = []; private readonly Queue pendingEvents = []; + [ObservableProperty] private bool activated; private bool clearing; + + [ObservableProperty] + private int count; + + private IDispatcher dispatcher; + [ObservableProperty] private bool initialized; [ObservableProperty] private TItem? selectedItem; - - private IDispatcher dispatcher; public ObservableCollection(IServiceProvider provider, IServiceFactory factory, IMediator mediator, @@ -92,9 +97,6 @@ public partial class ObservableCollection : public event NotifyCollectionChangedEventHandler? CollectionChanged; public event EventHandler? DeactivateHandler; - - public int Count => collection.Count; - public IDisposer Disposer { get; private set; } public IServiceFactory Factory { get; private set; } @@ -282,22 +284,6 @@ public partial class ObservableCollection : return Task.CompletedTask; } - private void UpdateSelection(TItem item) - { - if (item is ISelectable newSelection) - { - if (newSelection.Selected) - { - if (SelectedItem is ISelectable oldSelection) - { - oldSelection.Selected = false; - } - - dispatcher.Invoke(() => SelectedItem = item); - } - } - } - public Task Handle(InsertEventArgs args) { if (Activated) @@ -564,8 +550,27 @@ public partial class ObservableCollection : private static bool IsCompatibleObject(object? value) => (value is TItem) || (value == null && default(TItem) == null); - private void OnCollectionChanged(object? sender, NotifyCollectionChangedEventArgs args) => + private void OnCollectionChanged(object? sender, NotifyCollectionChangedEventArgs args) + { + Count = collection.Count; CollectionChanged?.Invoke(this, args); + } + + private void UpdateSelection(TItem item) + { + if (item is ISelectable newSelection) + { + if (newSelection.Selected) + { + if (SelectedItem is ISelectable oldSelection) + { + oldSelection.Selected = false; + } + + dispatcher.Invoke(() => SelectedItem = item); + } + } + } } public partial class ObservableCollection(IServiceProvider provider, diff --git a/Toolkit.UI.Avalonia/ItemInvokedEventArgs.cs b/Toolkit.UI.Avalonia/ItemInvokedEventArgs.cs index 58d809e..96f37a4 100644 --- a/Toolkit.UI.Avalonia/ItemInvokedEventArgs.cs +++ b/Toolkit.UI.Avalonia/ItemInvokedEventArgs.cs @@ -3,6 +3,4 @@ namespace Toolkit.UI.Avalonia; public class ItemInvokedEventArgs : - RoutedEventArgs -{ -} \ No newline at end of file + RoutedEventArgs; \ No newline at end of file