Question

I have very strange problem. Is there any possibility to have these two controls radio and newRadio have property IsChecked == true. Before code in line 6 is executed radio.IsChecked == true, but after executing code in line 6 radio.IsChecked == false and newRadio.IsChecked == true.

Is there any possibility that these two radio buttons will have IsChecked == true with the same GroupName?

1. RadioButton radio = new RadioButton();       

2. radio.GroupName = "group";
3. radio.IsChecked = true;          
4. radio.Name = "name";         

5. string xaml = XamlWriter.Save(radio);

6. var newRadio = XamlReader.Parse(xaml);
Was it helpful?

Solution

GroupName -> "Gets or sets the name that specifies which RadioButton controls are mutually exclusive."

So usually no, if multiple radio buttons share the same group code only one should be checked at a time.

As a hack you could change the group name for the first radio button, create the second, and then put it back. You should get both radio buttons checked, but this is not something I would recommend.

Example:

radio.GroupName = String.Empty;
var newRadio = XamlReader.Parse(xaml);
radio.GroupName = "group";
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top