0

Given an object with a flag variable:

[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();
                }
            }
        }
}

An ObjectDataProvider to access the Flags

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

And the Xceed CheckComboBox

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

At this stage it is showing the list of Flags with the check box. I would have assumed that I would need to:

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

I have tried what seems to me to be all other logical combinations (not to metion some ones that seem illogical too, any help would be appreciated).

Mark Wickman
  • 83
  • 1
  • 9
  • How are you supposed to bind several checked items to a single `Condition` property? – mm8 May 29 '20 at 11:15

1 Answers1

0

How are you supposed to bind several checked items to a single Condition property? You can't.

SelectedItemsOverride should be bound to an IList source property:

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

XAML:

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

If you only want to select a single value, you should use an ordinary ComboBox:

<ComboBox ItemsSource="{Binding Source={StaticResource enmCondition}}" 
          SelectedItem="{Binding Condition}" />
mm8
  • 163,881
  • 10
  • 57
  • 88