How to bind RadioButtons to an enum?

前端 未结 9 2241
日久生厌
日久生厌 2020-11-22 03:21

I\'ve got an enum like this:

public enum MyLovelyEnum
{
    FirstSelection,
    TheOtherSelection,
    YetAnotherOne
};

I got a property in

9条回答
  •  闹比i
    闹比i (楼主)
    2020-11-22 04:06

    This work for Checkbox too.

    public class EnumToBoolConverter:IValueConverter
    {
        private int val;
        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            int intParam = (int)parameter;
            val = (int)value;
    
            return ((intParam & val) != 0);
        }
    
        public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
        {
            val ^= (int)parameter;
            return Enum.Parse(targetType, val.ToString());
        }
    }
    

    Binding a single enum to multiple checkboxes.

提交回复
热议问题