I'm using Xceed Extended WPF Toolkit to display a enum with [Flags] attribute in a PropertyGrid
[Flags]
public enum TestEnum
{
Because I can't know the enum definition at compile time, I would dynamically create an Enum using EnumBuilder. ( I can't rely on a compile-time enum. I would dynamically create an Enum using [EnumBuilder])
I created an editor to display the enum as CheckComboBox:
public class CheckComboBoxEditor : TypeEditor<CheckComboBox>, ITypeEditor
{
As you can see, so far I've tried to bind each the SelectedValue and the SelectedItem property. CreateValueConverter() is defined in the base class and returns null.
It works well if I select some Values in the box and hit my save Button - in my model, I receive the correct enum value. But it doesn't work in the other direction - if i set any enum value (with or without flags) to my property, all values are unchecked and the content area is empty.
Do you have any idea to solve this problem?
[Flags]
public enum TestEnum
{
Test1 = 1,
Test2 = 2,
Test3 = 4,
Test4 = 8,
Test5 = 16,
Test6 = 32,
Test7 = 64,
}Because I can't know the enum definition at compile time, I would dynamically create an Enum using EnumBuilder. ( I can't rely on a compile-time enum. I would dynamically create an Enum using [EnumBuilder])
I created an editor to display the enum as CheckComboBox:
public class CheckComboBoxEditor : TypeEditor<CheckComboBox>, ITypeEditor
{
protected override void SetValueDependencyProperty()
{
ValueProperty = CheckComboBox.SelectedValueProperty;
}
protected override CheckComboBox CreateEditor()
{
return new CheckComboBox();
}
protected override void ResolveValueBinding(PropertyItem propertyItem)
{
var _binding = new Binding("Value");
_binding.Source = propertyItem;
_binding.UpdateSourceTrigger = UpdateSourceTrigger.PropertyChanged;
_binding.Mode = BindingMode.TwoWay;
_binding.Converter = CreateValueConverter();
BindingOperations.SetBinding(Editor, CheckComboBox.SelectedValueProperty, _binding);
var _binding2 = new Binding("Value");
_binding2.Source = propertyItem;
_binding2.UpdateSourceTrigger = UpdateSourceTrigger.PropertyChanged;
_binding2.Mode = BindingMode.TwoWay;
_binding2.Converter = CreateValueConverter();
BindingOperations.SetBinding(Editor, CheckComboBox.SelectedItemProperty, _binding2);
Editor.ItemsSource = Enum.GetValues(propertyItem.Value.GetType());
}
}As you can see, so far I've tried to bind each the SelectedValue and the SelectedItem property. CreateValueConverter() is defined in the base class and returns null.
It works well if I select some Values in the box and hit my save Button - in my model, I receive the correct enum value. But it doesn't work in the other direction - if i set any enum value (with or without flags) to my property, all values are unchecked and the content area is empty.
Do you have any idea to solve this problem?