diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/Data/CollectionViewGroupInternal.cs b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/Data/CollectionViewGroupInternal.cs index c844a5420fd..c4c4070dd13 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/Data/CollectionViewGroupInternal.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/Data/CollectionViewGroupInternal.cs @@ -87,11 +87,11 @@ internal GroupDescription GroupBy ListCollectionView.PrepareComparer( _groupBy.CustomSort, _groupBy.SortDescriptionsInternal, - () => + static state => { - for (CollectionViewGroupInternal group = this; - group != null; - group = group.Parent) + for (CollectionViewGroupInternal group = (CollectionViewGroupInternal)state; + group != null; + group = group.Parent) { CollectionViewGroupRoot root = group as CollectionViewGroupRoot; if (root != null) @@ -100,7 +100,7 @@ internal GroupDescription GroupBy } } return null; // this should never happen - root should always be present - }); + }, this); if (oldIsBottomLevel != IsBottomLevel) { diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Data/ListCollectionView.cs b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Data/ListCollectionView.cs index 2fe20fd83c2..e9ddb8c0748 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Data/ListCollectionView.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Data/ListCollectionView.cs @@ -2447,7 +2447,7 @@ internal bool HasSortDescriptions // return an appropriate comparer. Common logic used by ListCollectionView // and by CollectionViewGroupInternal. - internal static IComparer PrepareComparer(IComparer customSort, SortDescriptionCollection sort, Func lazyGetCollectionView) + internal static IComparer PrepareComparer(IComparer customSort, SortDescriptionCollection sort, Func lazyGetCollectionView, object state) { if (customSort != null) { @@ -2456,7 +2456,7 @@ internal static IComparer PrepareComparer(IComparer customSort, SortDescriptionC if (sort != null && sort.Count > 0) { - CollectionView view = lazyGetCollectionView(); + CollectionView view = lazyGetCollectionView(state); Debug.Assert(view != null, "lazyGetCollectionView should not return null"); if (view.SourceCollection != null) @@ -2895,7 +2895,7 @@ private void AdjustCurrencyForReplace(int index) private void PrepareShaping() { // sort: prepare the comparer - ActiveComparer = ListCollectionView.PrepareComparer(_customSort, _sort, () => { return this; }); + ActiveComparer = PrepareComparer(_customSort, _sort, static state => (ListCollectionView)state, this); // filter: prepare the Predicate filter ActiveFilter = Filter;