Skip to content

Commit

Permalink
fix: Handle Reset action in OnCollectionChanged method
Browse files Browse the repository at this point in the history
Introduce code to handle NotifyCollectionChangedAction.Reset in the
OnCollectionChanged method. When a reset occurs, the code checks if
the sender is an IEnumerable, iterates through the items, and updates
the OnItemPropertyChangedCallbackAsync event handler for each item
implementing INotifyPropertyChanged. Finally, it calls the
RefreshAppointments method to ensure all items are properly updated.
  • Loading branch information
Stéphane ANDRE (E104915) committed Oct 16, 2024
1 parent 7b69e6c commit a63d72c
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions src/MyNet.Wpf/Controls/CalendarBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -366,7 +366,16 @@ private async void OnAppointmentsCollectionChangedCallbackAsync(object? sender,
if (_refreshAppointmentsSuspender.IsSuspended) return;

if (e.Action == NotifyCollectionChangedAction.Reset)
{
if (sender is IEnumerable enumerable)
foreach (var item in enumerable.OfType<INotifyPropertyChanged>())
{
item.PropertyChanged -= OnItemPropertyChangedCallbackAsync;
item.PropertyChanged += OnItemPropertyChangedCallbackAsync;
}

RefreshAppointments();
}
else
{
await Dispatcher.Invoke(() => BusyService).WaitAsync<IndeterminateBusy>(async _ =>
Expand Down

0 comments on commit a63d72c

Please sign in to comment.