XAML band radio buttons

I have six switches in XAML and I would like to create two groups. It seems that WPF does not have a radioobutton group member, so how can I do this?

+7
source share
2 answers

You must provide a group_name for the item.

<RadioButton GroupName="Group1"/> 
+16
source

BitKFu's suggestion of using the GroupName property will work, but there is a caveat. If you use group names, the scope for the RadioButton groups becomes different.

If you create a UserControl with 3 RadioButtons all with GroupName from "MyRadioGroup" and put 2 such controls in your Window , you will notice that all 6 RadioButton act as if they are one group.

This is because when RadioButton updates another RadioButton , it usually sets up RadioButton , which are children of its immediate parent DependencyObject . However, when GroupName used, the area expands to the root of Visual ( Window , for example), and it will configure all RadioButton under this root, which have the same GroupName .

Therefore, sometimes it is better to simply separate them with an additional panel.

+10
source

All Articles