Как привязать переменную Flag к Xceed CheckComboBox - PullRequest
0 голосов
/ 29 мая 2020

Для объекта с переменной-флагом:

[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 для доступа к Flags

<ObjectDataProvider x:Key="enmCondition" MethodName="GetValues" ObjectType="{x:Type core:Enum}">
            <ObjectDataProvider.MethodParameters>
                <x:Type TypeName="enm:fCondition"></x:Type>
            </ObjectDataProvider.MethodParameters>
</ObjectDataProvider>   

И Xceed CheckComboBox

<xctk:CheckComboBox  ItemsSource="{Binding Source={StaticResource enmCondition}}" />

На этом На этапе отображается список флагов с флажком. Я бы предположил, что мне нужно:

SelectedItemsOverride="{Binding Path=Condition, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"

Я пробовал то, что мне кажется всеми другими логическими комбинациями (не говоря уже о некоторых, которые тоже кажутся нелогичными, любая помощь будет принята с благодарностью).

1 Ответ

0 голосов
/ 29 мая 2020

Как вы должны привязать несколько отмеченных элементов к одному свойству Condition? Вы не можете.

SelectedItemsOverride должен быть привязан к свойству источника IList:

 public List<fCondition> SelectedConditions { get; } = new List<fCondition>();

XAML:

<xctk:CheckComboBox  ItemsSource="{Binding Source={StaticResource enmCondition}}" 
                     SelectedItemsOverride="{Binding SelectedConditions}" />

Если вы только хотите чтобы выбрать значение single , вы должны использовать обычное ComboBox:

<ComboBox ItemsSource="{Binding Source={StaticResource enmCondition}}" 
          SelectedItem="{Binding Condition}" />
...