![](https://i-blog.csdnimg.cn/blog_migrate/8f900a89c6347c561fdf2122f13be562.gif)
![](https://i-blog.csdnimg.cn/blog_migrate/961ddebeb323a10fe0623af514929fc1.gif)
<RadioButton Margin="0,6,0,0" VerticalAlignment="Center" Grid.Row="0" Grid.Column="1" AutomationProperties.AutomationId="MaleRadioButton" Content="{DynamicResource ResourceKey=PM_Male}" IsChecked="{Binding Gender, Mode=TwoWay, Converter={StaticResource enumToBooleanConverter1}, ConverterParameter={x:Static inf:Gender.Male}}"/> <RadioButton Margin="0,6,0,0" VerticalAlignment="Center" Grid.Row="1" Grid.Column="1" AutomationProperties.AutomationId="FemaleRadioButton" Content="{DynamicResource ResourceKey=PM_Female}" IsChecked="{Binding Gender, Mode=TwoWay, Converter={StaticResource enumToBooleanConverter1}, ConverterParameter={x:Static inf:Gender.Female}}"/> <RadioButton Margin="0,6,0,11" VerticalAlignment="Center" Grid.Row="2" Grid.Column="1" AutomationProperties.AutomationId="UnkonwnRadioButton" Content="{DynamicResource ResourceKey=PM_Unkonwn}" IsChecked="{Binding Gender, Mode=TwoWay, Converter={StaticResource enumToBooleanConverter1}, ConverterParameter={x:Static inf:Gender.Unkonwn}}"/>
转换类
![](https://i-blog.csdnimg.cn/blog_migrate/8f900a89c6347c561fdf2122f13be562.gif)
![](https://i-blog.csdnimg.cn/blog_migrate/961ddebeb323a10fe0623af514929fc1.gif)
public class EnumToBooleanConverter : IValueConverter { public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture) { return ((Enum)value).HasFlag((Enum)parameter); } public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture) { return value.Equals(true) ? parameter : Binding.DoNothing; } }
enum
![](https://i-blog.csdnimg.cn/blog_migrate/8f900a89c6347c561fdf2122f13be562.gif)
![](https://i-blog.csdnimg.cn/blog_migrate/961ddebeb323a10fe0623af514929fc1.gif)
public enum Gender { Default, Male, Female, Unkonwn }
如果不给gender写一个defult的enum。。。如果前台选中一个radiobutton(isChecked=true)。。然后再点击一下这个radiobutton。。会出现第一个radiobutton也被选上的bug。。解决办法。。给它加一个。。不需要的enum值。。作为第一个。。