I have got a reference to a RadioButton rb1.
How can I get the index of the selected RadioButton in rb1's group ?
I have googled for a while but without success.
Any help will be greatly appreciated
I have got a reference to a RadioButton rb1.
How can I get the index of the selected RadioButton in rb1's group ?
I have googled for a while but without success.
Any help will be greatly appreciated
Well short answer to your question is you don't. What you should do is bind
RadioButton.IsChecked
to somebool
property of your view model. You can achieve something like group index by bindingint
property of your view model via your implementation ofIValueConverter
:View Model property:
Converter:
and then you bind it like this:
In this case your view model property
GroupIndex
will have values 1, 2 or 3 depending on whatRadioButton
is tickedIf you got to this point then there is probably something wrong with your design and you should reconsider it.
that being said you could traverse the visual tree and find it like this:
then go over the children and find the checked radioButton