绑定到RadioButtons Ischecked在取消选中后被清除

jma*_*yor 1 data-binding wpf xaml wpf-controls

我有一个radioButton组,每个Button绑定到一个Enum属性

<RadioButton Name="rbFixedDiscount" IsChecked="{Binding Path=DiscountType, Mode=TwoWay, Converter={StaticResource EnumConverter},ConverterParameter=Fixed, UpdateSourceTrigger=PropertyChanged}" >Fixed:</RadioButton>

<RadioButton Name="rbPercentDiscount" Grid.Row="1" IsChecked="{Binding Path=DiscountType, Mode=TwoWay, Converter={StaticResource EnumConverter},ConverterParameter=Percent, UpdateSourceTrigger=PropertyChanged}">Percent:</RadioButton>

<RadioButton Name="rbFreeNightsDiscount" Grid.Row="2" IsChecked="{Binding Path=DiscountType, Mode=TwoWay, Converter={StaticResource EnumConverter},ConverterParameter=FreeNights, UpdateSourceTrigger=PropertyChanged}">Free Nights:</RadioButton>
Run Code Online (Sandbox Code Playgroud)

每当我在UI中来回点击时,后面的属性只有在我点击一个新的RB时才会更新,如果我单击其中一个按钮(所以我将其设为Checked - > Unchecked - > Checked),绑定后面的属性不会刷新,它的绑定已被清除我认为这是因为取消选中和Item时调用ClearValue().无论如何,我可以在来回点击时保持绑定活着.

Ben*_*ier 5

这是一个带有单选按钮的已知且烦人的错误.幸运的是,有一些解决方法,这里有一些我见过的:

  1. 将列表框重新设置为单选按钮,然后使用它.
  2. 在控件模板中声明绑定.(链接)
  3. 将每个单选按钮放在不同的组中,并通过值转换器控制其已检查/未检查的属性.(链接)

希望其中一个解决方案能为您服务!