• Enum 타입
public enum FilterType { None, Size, Perent }

  • Converter 정의
class EnumToBooleanConverter : IValueConverter
{
    public object Convert(object value, Type targetType, 
                          object parameter, CultureInfo culture)
    {
        return value.Equals(parameter);
    }

    public object ConvertBack(object value, Type targetType, 
                              object parameter, CultureInfo culture)
    {
        return value.Equals(true) ? parameter : Binding.DoNothing;
    }
}

  • xaml 바인딩
<RadioButton IsChecked="{Binding FilterOption,    
                         ConverterParameter={x:Static service:FilterType.NONE}, 
                         Converter={StaticResource EnumToBoolean}}" .../>

<RadioButton IsChecked="{Binding FilterOption,    
                         ConverterParameter={x:Static service:FilterType.Size}, 
                         Converter={StaticResource EnumToBoolean}}" .../>

<RadioButton IsChecked="{Binding FilterOption,    
                         ConverterParameter={x:Static service:FilterType.Perent }, 
                         Converter={StaticResource EnumToBoolean}}" .../>

참고

https://stackoverflow.com/questions/397556/how-to-bind-radiobuttons-to-an-enum

카테고리:

업데이트:

댓글남기기