У меня есть «ListView» с использованием «DataTemplate» следующим образом («UserControl»):
<ListBox VerticalAlignment="Stretch"
SelectionMode="Single" ItemsSource="{Binding Source}" Visibility="{Binding Visibility}">
<ListBox.ItemsPanel>
<ItemsPanelTemplate>
<VirtualizingStackPanel IsItemsHost="True" Orientation="{Binding Orientation}"/>
</ItemsPanelTemplate>
</ListBox.ItemsPanel>
<ListBox.Resources>
<Style TargetType="ListBoxItem">
<Setter Property="OverridesDefaultStyle" Value="true"/>
<Setter Property="SnapsToDevicePixels" Value="true"/>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="ListBoxItem">
<RadioButton
GroupName="{Binding GroupName}"
Foreground="Black"
Margin="5,2"
IsChecked="{TemplateBinding IsSelected}">
<RadioButton.Resources>
<!--Unchecked state-->
<SolidColorBrush x:Key="MaterialDesignCheckBoxOff" Color="#ced4da"/>
<!--Checked state-->
<SolidColorBrush x:Key="PrimaryHueMidBrush" Color="#3e97eb"/>
</RadioButton.Resources>
<ContentPresenter/>
</RadioButton>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
</ListBox.Resources>
Я использую этот «ListBox» («UserControl») четыре раза в «MainWindowView», поэтому я должен использовать «GroupName». но "Binding GroupName" не работает.
Обновление Моя проблема решена:
IsChecked="{Binding Path=IsSelected,
RelativeSource={RelativeSource TemplatedParent},
Mode=TwoWay}"