scm 代表
xmlns:scm="clr-namespace:System.ComponentModel;assembly=WindowsBase"
有一个适合我的解决方案。您必须根据您的情况对其进行调整:
<Window.Resources>
<CollectionViewSource x:Key="customerGroups" Source="{Binding Path=Customers}">
<CollectionViewSource.GroupDescriptions>
<PropertyGroupDescription PropertyName="IsCompany"></PropertyGroupDescription>
</CollectionViewSource.GroupDescriptions>
<CollectionViewSource.SortDescriptions>
<scm:SortDescription PropertyName="IsCompany" Direction="Descending"/>
<scm:SortDescription PropertyName="DisplayName" Direction="Ascending"/>
</CollectionViewSource.SortDescriptions>
</CollectionViewSource>
</Window.Resources>
然后将此资源作为 ComboBox 的 ItemsSource 引用,并将内容绑定到所需的属性:
<ComboBox ItemsSource="{Binding Source={StaticResource customerGroups}}">
<DataTemplate>
<TextBlock Text="{Binding Path= FirstName}"></TextBlock>
</DataTemplate>
</ComboBox>