【发布时间】:2020-05-25 22:58:09
【问题描述】:
我使用以下 XAML 为 WPF 组合框实现了排序:
<CollectionViewSource x:Key="SortedAreas" Source="{Binding AllAreas}">
<CollectionViewSource.SortDescriptions>
<scm:SortDescription PropertyName="Name"/>
</CollectionViewSource.SortDescriptions>
</CollectionViewSource>
<ComboBox Name="PhotoLocationAreaComboBox"
ItemsSource="{Binding Source={StaticResource SortedAreas}}"
DisplayMemberPath="Name">
</ComboBox>
这基本上可以正常工作 - 条目已排序,但有一个副作用:
- 在我添加排序之前(直接绑定到作为 ObservableCollection 的 AllAreas,内部没有选择组合框条目(空)
- 排序后,自动预选第一个排序的条目
知道如何通过排序恢复原始行为(未选择条目)吗?我试过 SelectedIndex = "0",但这没有帮助。
【问题讨论】:
-
SelectedIndex = -1 它不是 0 表示没有条目,但我不确定是否能解决您的问题
标签: wpf sorting xaml combobox collectionviewsource