From 14a522d09493aeeb737637908be7a4b6749df432 Mon Sep 17 00:00:00 2001 From: Adam Date: Tue, 11 Apr 2023 23:15:36 -0400 Subject: [PATCH] Fix DataGrid scroll performance issues - fixes #2122 --- .../DataGrid/DataGridDataConnection.cs | 18 ++++++------------ 1 file changed, 6 insertions(+), 12 deletions(-) diff --git a/CommunityToolkit.WinUI.UI.Controls.DataGrid/DataGrid/DataGridDataConnection.cs b/CommunityToolkit.WinUI.UI.Controls.DataGrid/DataGrid/DataGridDataConnection.cs index fa806503206..6ce38f57e7b 100644 --- a/CommunityToolkit.WinUI.UI.Controls.DataGrid/DataGrid/DataGridDataConnection.cs +++ b/CommunityToolkit.WinUI.UI.Controls.DataGrid/DataGrid/DataGridDataConnection.cs @@ -123,13 +123,11 @@ public int Count return list.Count; } -#if FEATURE_PAGEDCOLLECTIONVIEW - PagedCollectionView collectionView = this.DataSource as PagedCollectionView; + var collectionView = this.DataSource as ICollectionView; if (collectionView != null) { return collectionView.Count; } -#endif int count = 0; IEnumerable enumerable = this.DataSource; @@ -498,13 +496,11 @@ public object GetDataItem(int index) return (index < list.Count) ? list[index] : null; } -#if FEATURE_PAGEDCOLLECTIONVIEW - PagedCollectionView collectionView = this.DataSource as PagedCollectionView; + var collectionView = this.DataSource as ICollectionView; if (collectionView != null) { - return (index < collectionView.Count) ? collectionView.GetItemAt(index) : null; + return (index < collectionView.Count) ? collectionView[index] : null; } -#endif IEnumerable enumerable = this.DataSource; if (enumerable != null) @@ -579,13 +575,11 @@ public int IndexOf(object dataItem) return list.IndexOf(dataItem); } -#if FEATURE_PAGEDCOLLECTIONVIEW - PagedCollectionView cv = this.DataSource as PagedCollectionView; - if (cv != null) + var collectionView = this.DataSource as ICollectionView; + if (collectionView != null) { - return cv.IndexOf(dataItem); + return collectionView.IndexOf(dataItem); } -#endif IEnumerable enumerable = this.DataSource; if (enumerable != null && dataItem != null)