I want to sort a CollectionViewSource
but i need to set a condition instead of PropertyName
.In Fact i want to do the sort below using CollectionViewSource
in Xaml
.
我想对CollectionViewSource进行排序,但我需要设置一个条件而不是PropertyName。事实上,我想在Xaml中使用CollectionViewSource进行下面的排序。
Class2Colection.OrderBy(s => s.Id).OrderBy(s =>!s.Id.HasValue));
<CollectionViewSource Source="{Binding Class2Colection}">
<CollectionViewSource.SortDescriptions>
<scm:SortDescription PropertyName="Id" Direction="Ascending"/>
<scm:SortDescription PropertyName="??" Direction="Ascending"/>
</CollectionViewSource.SortDescriptions>
</CollectionViewSource>
1 个解决方案
#1
0
You can apply custom sorting logic by implementing your own IComparer
and setting it to public CustomSort
property of ListCollectionView
class. But this is not complete answer to your question and rather a direction where you can move forward.
您可以通过实现自己的IComparer并将其设置为ListCollectionView类的公共CustomSort属性来应用自定义排序逻辑。但这不是你问题的完整答案,而是你可以前进的方向。
The simplest way you can achieve just this
最简单的方法就是实现这一目标
Class2Colection.OrderBy(s => s.Id).OrderBy(s =>!s.Id.HasValue));
in xaml
is to expose another property in your data class which whould return !Id.HasValue
and sort by it.
在xaml中是为了暴露你的数据类中的另一个属性,它将返回!Id.HasValue并按它排序。
#1
0
You can apply custom sorting logic by implementing your own IComparer
and setting it to public CustomSort
property of ListCollectionView
class. But this is not complete answer to your question and rather a direction where you can move forward.
您可以通过实现自己的IComparer并将其设置为ListCollectionView类的公共CustomSort属性来应用自定义排序逻辑。但这不是你问题的完整答案,而是你可以前进的方向。
The simplest way you can achieve just this
最简单的方法就是实现这一目标
Class2Colection.OrderBy(s => s.Id).OrderBy(s =>!s.Id.HasValue));
in xaml
is to expose another property in your data class which whould return !Id.HasValue
and sort by it.
在xaml中是为了暴露你的数据类中的另一个属性,它将返回!Id.HasValue并按它排序。