how to sort ObservableCollection

前端 未结 5 692
轮回少年
轮回少年 2020-12-08 06:00

I have a an ObservableCollection and a WPF UserControl is Databound to it. The Control is a graph that shows a vertical bar for each item of type BarData in the ObservableCo

5条回答
  •  被撕碎了的回忆
    2020-12-08 06:27

    hummm first question I have for you is: is it really important that your ObservableCollection is sorted, or is what you really want is to have the display in GUI sorted?

    I assume that the aim is to have a sorted display that will be updated "real time". Then I see 2 solutions

    1. get the ICollectionView of your ObservableCollection and sort it, as explained here http://marlongrech.wordpress.com/2008/11/22/icollectionview-explained/

    2. bind your ObservableCollection to a CollectionViewsource, add a sort on it, then use thatCollectionViewSource as the ItemSource of a ListView.

    i.e:

    add this namespace

    xmlns:scm="clr-namespace:System.ComponentModel;assembly=WindowsBase"
    

    then

    
        
            
        
    
    
    

    and bind like this

    
    

提交回复
热议问题