WPF : 6. RadioButton의 IsChecked프로퍼티와 Enum타입 바인딩하는 법
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
댓글남기기