How to get Items count from CollectionViewSource?

后端 未结 6 724
鱼传尺愫
鱼传尺愫 2021-01-17 09:19

I am using CollectionViewSource to filter the records displayed in a ListBox. The xaml follows.

   

        
6条回答
  •  甜味超标
    2021-01-17 09:40

    The source collection and collectionview both implements IEnumerable so you can always iterate over them and count how many are in them. But I would only recommend doing this if you have no access to the actual collection you used as source.

    private void SetSummary() 
    {
        int initialCount = 0;
        foreach(var item in _viewSource.View.SourceCollection)
        {
            initialCount++;
        }
    
        int filteredCount = 0;
        foreach (var item in _viewSource.View)
        {
            filteredCount++;
        }
    }
    

提交回复
热议问题