0

I have 2 RadioButton element on each row item of my ListView. If I put the IsChecked attribute on my 2 RadioButton, my WPF application does not allow me to select any of the RadioButton on every row item of my list. Did I miss something? or am I doing it wrong? Please enlighten me.

<StackPanel>
<RadioButton Content="{Binding choice1}" GroupName="{Binding number}" x:Name="btn_radio1" IsChecked="{Binding IsRadioChecked}"></RadioButton>
<RadioButton Content="{Binding choice2}" GroupName="{Binding number}" x:Name="btn_radio2" IsChecked="{Binding IsRadioChecked}"></RadioButton>
</StackPanel>
Marss
  • 573
  • 2
  • 7
  • 24
  • 2
    You bind both to the same `IsRadioChecked` property and they cannot be both checked – dkozl Feb 01 '14 at 12:37
  • I see. So, I need to create different properties for each RadioButton element I add or is there a way to just create one property that checks all the value of my RadioButton element? – Marss Feb 01 '14 at 12:39
  • This or one `int` or `enum` property and converter like [here](http://stackoverflow.com/questions/17082551/getting-the-index-of-the-selected-radiobutton-in-a-group/17083179#17083179) – dkozl Feb 01 '14 at 12:42
  • Thank you for enlightening me about this. I tried creating 2 properties to check the value of each RadioButton and it worked. I'll try to read on the link you provided. Hope I can get it. I appreciate your help. – Marss Feb 01 '14 at 12:45

1 Answers1

1

This code will not work as two radio button with same group name is binded with same IsRadioChecked property, because at a time only one radio button can be checked. if you want both to be checked at a same time its better to use CHECKBOX control

As well as you should use two different IsRadioChecked property IsRadioChecked1 and IsRadioChecked2 in case of checkbox else at both checkbox will have same state

If still you want to use radio button first you decide IsRadioChecked is for choice1 or choice2 if it meant for choice1 remove IsChecked="{Binding IsRadioChecked}" from choice2

slash shogdhe
  • 3,943
  • 6
  • 27
  • 46