views:

51

answers:

1

I have a radioButton group and each Button is binded to an Enum property

<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>

Whenever I click back and forth in the UI the property behind only gets updated when I click a new RB, If I click one of the buttons back ( so I make it Checked -> Unchecked -> Checked) the property behind the binding doesn't refresh, it's binding has been cleared I think it is because the ClearValue() gets called when unchecking and Item. Anyway I can keep the binding alive while clicking back and forth.

+2  A: 

This is a known and annoying bug with radio buttons. Fortunately, there are a few workarounds, here are a few that I've seen:

  1. Restyle a listbox as a radio button and use that instead.
  2. Declare the binding in a control template. (link)
  3. Put each radio button in a different group and control their checked/unchecked property through a value converter. (link)

Hopefully one of those solutions will work for you!

Ben Collier