重复我有一个ObservableCollection<M> fooBar {get;set;}
。类M.cs
看起来是这样的:WPF隐藏与CollectionViewSource
public class M{
private int _ID;
public int ID {
get {return this._ID;}
set {this._ID = value;}
}
private string _number;
public int Number {
get {return this._number;}
set {this._number = value;}
}
private string _power;
public int Power {
get {return this._power;}
set {this._power = value;}
}
/*
...
*/
}
现在我想只隐藏属性格式Power
的副本。在我的.xaml
代码我写了这个:
<UserControl.Resources>
<CollectionViewSource x:Key="myCollection" Source="{Binding Path=fooBar}">
<CollectionViewSource.GroupDescriptions>
<PropertyGroupDescription PropertyName="Power"/>
</CollectionViewSource.GroupDescriptions>
</CollectionViewSource>
</UserControl.Resources>
我这个集合绑定到我的ComboBox
。
<ComboBox Name="cbValues"
ItemsSource="{Binding Source={StaticResource myCollection}}"
DisplayMemberPath="{Binding Power}"
SelectedValuePath="{Binding Power}"
/>
该ComboBox
填写正确的值,但仍有重复。我怎样才能隐藏它们?
填写资料的收集 – Eldho
尽可能避免重复数据WPF Combobox中的[Distinct Values]的副本(http://stackoverflow.com/questions/5995989/distinct-values-in-wpf-combobox) –
@Eldho不同的机器可以拥有相同的电源。 – MyNewName