给定一个带有标志变量的对象:
[Flags]
public enum fCondition
{
Scuffed = 1,
Torn = 2,
Stained = 4
}
public class AnEntity : TableEntity, INotifyPropertyChanged
{
public event PropertyChangedEventHandler PropertyChanged;
// This method is called by the Set accessor of each property.
// The CallerMemberName attribute that is applied to the optional propertyName
// parameter causes the property name of the caller to be substituted as an argument.
private void NotifyPropertyChanged([CallerMemberName] String propertyName = "")
{
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
}
public int ConditionID { get; set; }
public fCondition Condition
{
get => (fCondition)ConditionID;
set {
if (value != (fCondition)this.ConditionID)
{
this.ConditionID = (int)value;
NotifyPropertyChanged();
}
}
}
}
用于访问标志的对象数据提供程序
<ObjectDataProvider x:Key="enmCondition" MethodName="GetValues" ObjectType="{x:Type core:Enum}">
<ObjectDataProvider.MethodParameters>
<x:Type TypeName="enm:fCondition"></x:Type>
</ObjectDataProvider.MethodParameters>
</ObjectDataProvider>
和Xceed组合框
<xctk:CheckComboBox ItemsSource="{Binding Source={StaticResource enmCondition}}" />
在此阶段,它显示带有复选框的标志列表。 我本以为我需要:
SelectedItemsOverride="{Binding Path=Condition, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"
我已经尝试了在我看来是所有其他逻辑组合的东西(不要说一些看起来不合逻辑的组合,任何帮助将不胜感激(。
如何将多个选中的项目绑定到单个Condition
属性?你不能。
SelectedItemsOverride
应绑定到IList
源属性:
public List<fCondition> SelectedConditions { get; } = new List<fCondition>();
XAML:
<xctk:CheckComboBox ItemsSource="{Binding Source={StaticResource enmCondition}}"
SelectedItemsOverride="{Binding SelectedConditions}" />
如果只想选择单个值,则应使用普通ComboBox
:
<ComboBox ItemsSource="{Binding Source={StaticResource enmCondition}}"
SelectedItem="{Binding Condition}" />