Convert a List into an ObservableCollection

前端 未结 3 1005
终归单人心
终归单人心 2021-01-31 00:40

I have a List which is being populated from JSON. I need to convert it into an ObservableCollection to bind it to my GridView

3条回答
  •  南方客
    南方客 (楼主)
    2021-01-31 01:39

    ObservableCollection < T > has a constructor overload which takes IEnumerable < T >

    Example for a List of int:

    ObservableCollection myCollection = new ObservableCollection(myList);
    

    One more example for a List of ObjectA:

    ObservableCollection myCollection = new ObservableCollection(myList as List);
    

提交回复
热议问题