C# 如何在C中设置CollectionView的SortDescriptions#

C# 如何在C中设置CollectionView的SortDescriptions#,c#,wpf,xaml,sorting,C#,Wpf,Xaml,Sorting,我已经在XAML中定义了SortDescriptions和GroupDescriptions <CollectionViewSource x:Key="DefaultGrouping" Source="{Binding Projects}"> <CollectionViewSource.SortDescriptions> <componentModel:SortDescription Prope

我已经在XAML中定义了SortDescriptions和GroupDescriptions

        <CollectionViewSource x:Key="DefaultGrouping" Source="{Binding Projects}">
            <CollectionViewSource.SortDescriptions>
                <componentModel:SortDescription PropertyName="ProjectName" Direction="Ascending" />
                <componentModel:SortDescription PropertyName="CreationDate" Direction="Descending"/>
                <componentModel:SortDescription PropertyName="LastUsedTime" Direction="Descending"/>
            </CollectionViewSource.SortDescriptions>
            <CollectionViewSource.GroupDescriptions>
                <PropertyGroupDescription PropertyName="Default"/>
            </CollectionViewSource.GroupDescriptions>
        </CollectionViewSource>

现在我想更改viewmodel代码中的SortDescriptions。但是通过下面的代码,我得到了一个空的ListCollectionView

CollectionViewSource.GetDefaultView(this.Projects)


有没有办法获得正确的CollectionView?

您是否尝试过命名
CollectionViewSource
,然后按名称引用它?Project是一个IDynamicViewModelCollection和my viewmodel的属性,但可能是任何类型的列表。