Hello,
Welcome to Microsoft Q&A!
The reason for this behavior is that when applying the filter, the AdvancedCollectionView
will remove the items inside it and there must be at least one item in the collection, otherwise it will gives error - Index was out of range. To check this, you could take a look at the source code of the AdvancedCollectionView.
Also, When you are using the try/catch block to handling the error, the actual value of AdvancedCollectionView
is null. For example, you could get the ItemsSource of the DataGrid
and check its count. The last row you saw is actually some cache of the DataGrid, not the real data.
Currently, there is no way to avoid this when using the AdvancedCollectionView . You could report this on the WindowsCommunityToolkit Issues to see if the WindowsCommunityToolkit team could update this class.
A possible way is that you could try to directly download and modify the source code of AdvancedCollectionView
in the Github based on your request.
And another way is to use ObservableCollection
instead of AdvancedCollectionView
. For your pervious question, you might need to create the column by yourself and set AutoGenerateColumns to false. So it won't trigger the AutoGenerateColumns event when you sort the data. This is also the same way how the official document implement sorting and flitering.
Thank you.
If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.