how to sort ObservableCollection

前端 未结 5 672
轮回少年
轮回少年 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:19

    What about sorting the data using LINQ on the different collection:

    var collection = new List();
    //add few BarData objects to collection
    
    // sort the data using LINQ
    var sorted = from item in collection orderby item.StartData select item;
    
    // create observable collection
    var oc = new ObservableCollection(sorted);
    

    This worked for me.

提交回复
热议问题