Quantcast
Channel: Extended WPF Toolkit™ Community Edition
Viewing all articles
Browse latest Browse all 4964

New Post: CheckComboBox and [Flags] enum

$
0
0
Hi,

2 things.

1) Make sure your enum has the [Flags] attribute.

2) CheckComboBox.SelectedValue is a string of all the selectedItems separated by comma. Ex :
"Test2,Test3,Test4"
The EnumConverter.ConvertTo() method will convert "Test2 | Test3 | Test4" to
"Test2, Test3, Test4"
(note the spaces after the comma, which CheckComboBox.SelectedValue don't like).
You can use the ValueConverter in your CheckComboBoxEditor to remove those spaces :
 protected override IValueConverter CreateValueConverter()
      {
        return new MyConverter();
      }
where MyConverter is :
 public class MyConverter : IValueConverter
    {
      public object Convert( object value, Type targetType, object parameter, CultureInfo culture )
      {
        if( value == null )
          return null;

        var stringEnumValues = TypeDescriptor.GetConverter( value ).ConvertTo( value, typeof( string ) ) as string;
        return stringEnumValues.Replace( " ", string.Empty );
      }

      public object ConvertBack( object value, Type targetType, object parameter, CultureInfo culture )
      {
        if( value == null )
          return null;
        
        return TypeDescriptor.GetConverter( value ).ConvertFrom( value ) as string;
      }
    }

Viewing all articles
Browse latest Browse all 4964

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>