我有查看源代码
<view:ValidationBaseView x:Class="test.View.test"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:res="clr-namespace:test.Resources"
xmlns:local="clr-namespace:test"
xmlns:view="clr-namespace:test.View"
xmlns:viewModel="clr-namespace:test.ViewModel"
Height="Auto" Width="Auto">
<UserControl.DataContext>
<viewModel:testviewmodelx:Name="testview"/>
</UserControl.DataContext>
然后我有我的UI元素
我已经将组合框与ObservableCollection绑定(bind)了。但是我知道我需要在组合中排序值。
<ComboBox Grid.Column="0"
Grid.Row="3"
x:Name="combo1"
Margin ="0"
ItemsSource="{Binding Path=test}"
DisplayMemberPath="testpath"/>
最佳答案
使用ICollectionView
。像这样:
// this is your existing collection of items
var items = ...;
var cv = new ListCollectionView(items);
// this will sort by the Foo property of each item
cv.SortDescriptions.Add(new SortDescription("Foo"));
在您的 View 中,绑定(bind)到集合 View 而不是原始项目。
关于wpf - 如何对组合框的Observable集合进行排序,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/10194850/