我试图将分组的可观察集合传递给我的视图。
public void init()
{
people = CreatePeople( 20 ).ToList(); // Creates 20 person-objects
groupedPeople = ( from person in people
group person by person.City into g
orderby g.Key
select new Group<string, Person>
{
Key = g.Key.ToString(),
Items = g.ToList()
} ).ToList();
}
private IList<Person> people;
private IList<Group<string, Person>> groupedPeople; //Contains the groupedlist that i want to "convert"
public ObservableCollection<Group<string, Person>> gp; //This is the list I wish to pass to the view
为了让我通过列表,我需要在ObservableCollection
中public ObservableCollection<Group<string, Person>> gp;
我可以将private IList<Group<string, Person>>
“转换”为observableCollection吗?
答案 0 :(得分:1)
gp=new ObservableCollection(groupedPeople);
ObservableCollection的构造函数可以使用IList或IEnumerable