A common solution for me is to use a ListBox, which contains Selection behavior, and overwrite the Template to draw items as RadioButtons instead.
My XAML template usually looks something like this :
<Style x:Key="RadioButtonListBoxStyle" TargetType="{x:Type ListBox}">
<Setter Property="BorderBrush" Value="Transparent"/>
<Setter Property="KeyboardNavigation.DirectionalNavigation" Value="Cycle" />
<Setter Property="ItemContainerStyle">
<Setter.Value>
<Style TargetType="{x:Type ListBoxItem}" >
<Setter Property="Margin" Value="2, 2, 2, 0" />
<Setter Property="Template">
<Setter.Value>
<ControlTemplate>
<Border Background="Transparent">
<RadioButton
Content="{TemplateBinding ContentPresenter.Content}" VerticalAlignment="Center"
IsChecked="{Binding Path=IsSelected,RelativeSource={RelativeSource TemplatedParent},Mode=TwoWay}"/>
</Border>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
</Setter.Value>
</Setter>
</Style>
The style is applied like this:
<ListBox ItemsSource="{Binding Directions}"
SelectedValue="{Binding SelectedDirection}"
Style="{StaticResource RadioButtonListBoxStyle}" />
I find this much cleaner for managing selection behavior of grouped RadioButtons than maintaining a lot of IsChecked properties in my code-behind, or using converters.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…