C# WPF组合框/列表框或CollectionView的多个排序条件

C# WPF组合框/列表框或CollectionView的多个排序条件,c#,wpf,sorting,C#,Wpf,Sorting,我无法通过搜索找到以前的请求,这很奇怪。我只是尝试对绑定到组合框的集合视图应用多个排序条件 我试过这个: cmbRptCur.Items.SortDescriptions.Add(new SortDescription("Length", ListSortDirection.Ascending)); cmbRptCur.Items.SortDescriptions.Add(new SortDescription("Content", ListSortDirection.Ascending));

我无法通过搜索找到以前的请求,这很奇怪。我只是尝试对绑定到组合框的集合视图应用多个排序条件

我试过这个:

cmbRptCur.Items.SortDescriptions.Add(new SortDescription("Length", ListSortDirection.Ascending));
cmbRptCur.Items.SortDescriptions.Add(new SortDescription("Content", ListSortDirection.Ascending));

但仅应用第一个排序条件。这是一个字符串列表,我希望首先按字符串的长度升序排序,在这个列表中,按字母升序排序。理想情况下,我想知道如何做到这两种方法,以便做出最佳选择:)

尝试以下示例:

var variable = ListSortDirection.Orderby(c => c.Length).ThenBy(n => n.Content)
或者类似的

或者这个:

var variable = (from c in ListSortDirections
         orderby c.Length, c.Content
         select row).ToList();

举个例子。

试试这个例子:

var variable = ListSortDirection.Orderby(c => c.Length).ThenBy(n => n.Content)
或者类似的

或者这个:

var variable = (from c in ListSortDirections
         orderby c.Length, c.Content
         select row).ToList();

作为一个例子。

谢谢,我决定尝试LINQ路线,尽管应该有另一种方法。我需要使用.Cast()以可查询的格式获取它,而且它工作得很好。我仍然想知道如何直接在combobox上完成,而不必求助于LINQ。i、 e.(从ListCollectionView.Cast()中的c按c.Length排序,c选择c.ToList());谢谢,我决定尝试LINQ路线,尽管应该有另一种方式。我需要使用.Cast()以可查询的格式获取它,而且它工作得很好。我仍然想知道如何直接在combobox上完成,而不必求助于LINQ。i、 e.(从ListCollectionView.Cast()中的c按c.Length排序,c选择c.ToList());