【WPF】值是枚举的RadioButton 绑定问题

1、RadioButton

2、IValueConverter

3、枚举

 

xaml实现

1 <RadioButton Content="单打热身" GroupName="wramupType" IsChecked="{Binding TrainType, Converter={StaticResource RadioButtonConverter},ConverterParameter=0}"/>
2 <RadioButton Content="双打热身" GroupName="wramupType" IsChecked="{Binding TrainType, Converter={StaticResource RadioButtonConverter},ConverterParameter=1}" />

Converter实现

 1 public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
 2 {
 3     MatchTrainType s = (MatchTrainType)value;
 4     return s == (MatchTrainType)int.Parse(parameter.ToString());
 5 }
 6 
 7 public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
 8 {
 9     bool isChecked = (bool)value;
10     if (!isChecked)
11     {
12         return null;
13     }
14     return (MatchTrainType)int.Parse(parameter.ToString());
15 }

注意:Converter带参数和枚举的顺序

posted @ 2016-10-13 13:48  oiliu  阅读(1384)  评论(0编辑  收藏  举报