Add elements from IList to ObservableCollection

后端 未结 6 1695
臣服心动
臣服心动 2020-12-25 12:23

I have an ObservableCollection, and I\'d like to set the content of an IList to this one. Now I could just create a new instance of the collection..:

public         


        
6条回答
  •  鱼传尺愫
    2020-12-25 13:15

    If you do want to instantiate an observable collection and want to add a new range into Observable collection you can follow the following method I have tried:

    var list = new List();
                list.AddRange(order.ItemTransactions.ToShortTrans());
                list.AddRange(order.DealTransactions.ToShortTrans());
                ShortTransactions = new ObservableCollection(list);
    

    in this way you can add the range into ObservableCollection without looping.

提交回复
热议问题