wpf xaml data-binding radio-button

wpf - ¿Cómo puedo reducir el código de enlace de RadioButton?



xaml data-binding (1)

Estoy siguiendo esta respuesta sobre cómo enrutar las enum (entradas en mi caso) a RadioButtons , pero si tengo varios TabItems cada uno con 10x10 grillas de RadioButtons, ¿hay alguna manera de deshacerse de algunos de esos repetitivos? Como es, cada RadioButton tiene que tener toda esta información:

<RadioButton IsChecked="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type Window}}, Path=FavoriteColor, Converter={StaticResource IntToBoolConverter}, Mode=TwoWay, ConverterParameter=5}" Content="Red" Grid.Column="4" Grid.Row="6" />

Preferiblemente, me gustaría poder establecer el RelativeSource, el convertidor y el modo una vez en TabControl, la ruta una vez en cada TabItem, y solo tengo el parámetro ConverterParameter establecido por RadioButton. ¿Es esto posible en XAML? Si no, ¿hacerlo en código subyacente tiene más sentido?


Aquí hay una mejora en mi respuesta sobre una pregunta relacionada , utilizando el modo de selección única de ListBoxes :

<ListBox SelectionMode="Single" SelectedItem="{Binding EnumValue}" Style="{StaticResource BorderlessStyle}"> <ListBox.Resources> <ObjectDataProvider x:Key="items" MethodName="GetValues" ObjectType="{x:Type sys:Enum}"> <ObjectDataProvider.MethodParameters> <x:Type TypeName="local:MainWindow+TestEnum" /> </ObjectDataProvider.MethodParameters> </ObjectDataProvider> </ListBox.Resources> <ListBox.ItemsSource> <Binding Source="{StaticResource items}" /> </ListBox.ItemsSource> <ListBox.ItemsPanel> <ItemsPanelTemplate> <!-- Automatic grid layout, adjust as needed --> <UniformGrid Columns="2" /> </ItemsPanelTemplate> </ListBox.ItemsPanel> <ListBox.ItemTemplate> <DataTemplate> <RadioButton Content="{Binding}" IsChecked="{Binding IsSelected, RelativeSource={RelativeSource AncestorType=ListBoxItem}}" /> </DataTemplate> </ListBox.ItemTemplate> </ListBox>

El estilo para hacer que ListBox desaparezca:

<Style x:Key="BorderlessStyle" TargetType="ListBox"> <Setter Property="Template"> <Setter.Value> <ControlTemplate TargetType="ListBox"> <ItemsPresenter /> </ControlTemplate> </Setter.Value> </Setter> <Setter Property="ItemContainerStyle"> <Setter.Value> <Style TargetType="ListBoxItem"> <Setter Property="Template"> <Setter.Value> <ControlTemplate TargetType="ListBoxItem"> <ContentPresenter /> </ControlTemplate> </Setter.Value> </Setter> </Style> </Setter.Value> </Setter> </Style>