我怎样才能对ObservableCollection进行排序?

Jas*_*n94 7 c#

我试过了:

Persons = from i in Persons orderby i.Age select i;
Run Code Online (Sandbox Code Playgroud)

但我无法将Linqs转换System.Linq.IOrderedEnumerableObservableCollection<Person>.

Pho*_*cUK 18

您只需要创建一个新实例.

Persons = new ObservableCollection<Person>(from i in Persons orderby i.Age select i);
Run Code Online (Sandbox Code Playgroud)

  • 这可能会破坏使用`ObservableCollection`的任何绑定. (15认同)