From bfcd22679561318c29b9f715311bb8f876f621ec Mon Sep 17 00:00:00 2001 From: Michael Bucari-Tovo Date: Fri, 21 Mar 2025 11:08:36 -0600 Subject: [PATCH] Fix libation hanging on first inport of large libraries --- .../ViewModels/ProductsDisplayViewModel.cs | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/Source/LibationAvalonia/ViewModels/ProductsDisplayViewModel.cs b/Source/LibationAvalonia/ViewModels/ProductsDisplayViewModel.cs index 76193ae1..271feb44 100644 --- a/Source/LibationAvalonia/ViewModels/ProductsDisplayViewModel.cs +++ b/Source/LibationAvalonia/ViewModels/ProductsDisplayViewModel.cs @@ -164,6 +164,10 @@ namespace LibationAvalonia.ViewModels if (GridEntries == null) throw new InvalidOperationException($"Must call {nameof(BindToGridAsync)} before calling {nameof(UpdateGridAsync)}"); + //CollectionChanged fires for every book added, and the handler invokes + //VisibleCountChanged which triggers Libation to re-count all books. + GridEntries.CollectionChanged -= GridEntries_CollectionChanged; + #region Add new or update existing grid entries //Add absent entries to grid, or update existing entry @@ -214,8 +218,8 @@ namespace LibationAvalonia.ViewModels await Filter(FilterString); GC.Collect(GC.MaxGeneration, GCCollectionMode.Aggressive, true, true); - if (GridEntries != null) - GridEntries.CollectionChanged += GridEntries_CollectionChanged; + //Resubscribe after all changes to the list have been made + GridEntries.CollectionChanged += GridEntries_CollectionChanged; GridEntries_CollectionChanged(); }