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带参数和枚举的顺序

相关文章:

  • 2021-05-25
  • 2021-06-21
  • 2022-02-06
  • 2022-03-05
  • 2022-12-23
  • 2022-02-06
  • 2021-08-30
  • 2022-12-23
猜你喜欢
  • 2022-01-29
  • 2022-12-23
  • 2021-05-30
  • 2021-07-11
  • 2018-09-17
  • 2021-05-26
  • 2022-12-23
相关资源
相似解决方案