In order to set the same group to some RadioButton
s, you can set the GroupName
property of the RadioButton
s to the same value. For enabling a TextBox
according to the RadioButton
's state, you can use the ElementName
property of the Binding
. For instance, see the following StackPanel
:
<StackPanel>
<StackPanel Orientation="Horizontal" Margin="2">
<RadioButton Name="op1" Content="Option 1: " GroupName="A" />
<TextBox Width="200" IsEnabled="{Binding IsChecked, ElementName=op1}" />
</StackPanel>
<StackPanel Orientation="Horizontal" Margin="2">
<RadioButton Name="op2" Content="Option 2: " GroupName="A" />
<TextBox Width="200" IsEnabled="{Binding IsChecked, ElementName=op2}" />
</StackPanel>
<StackPanel Orientation="Horizontal" Margin="2">
<RadioButton Name="op3" Content="Option 3: " GroupName="A" />
<TextBox Width="200" IsEnabled="{Binding IsChecked, ElementName=op3}" />
</StackPanel>
<StackPanel Orientation="Horizontal" Margin="2">
<RadioButton Name="op4" Content="Option 4: " GroupName="A" />
<TextBox Width="200" IsEnabled="{Binding IsChecked, ElementName=op4}" />
</StackPanel>
<StackPanel Orientation="Horizontal" Margin="2">
<RadioButton Name="op5" Content="Option 5: " GroupName="A" />
<TextBox Width="200" IsEnabled="{Binding IsChecked, ElementName=op5}" />
</StackPanel>
</StackPanel>
Edited:
If you want the RadioButton
to be checked when you click on the disabled TextBox
, you can set the TextBox
as a part of the Content
of the RadioButton
, like in the following StackPanel
:
<StackPanel>
<RadioButton Name="op1" GroupName="A" Margin="2">
<RadioButton.Content>
<StackPanel Orientation="Horizontal">
<TextBlock Text="Option 1: " />
<TextBox Width="200" IsEnabled="{Binding IsChecked, ElementName=op1}" />
</StackPanel>
</RadioButton.Content>
</RadioButton>
<RadioButton Name="op2" GroupName="A" Margin="2">
<RadioButton.Content>
<StackPanel Orientation="Horizontal">
<TextBlock Text="Option 2: " />
<TextBox Width="200" IsEnabled="{Binding IsChecked, ElementName=op2}" />
</StackPanel>
</RadioButton.Content>
</RadioButton>
<RadioButton Name="op3" GroupName="A" Margin="2">
<RadioButton.Content>
<StackPanel Orientation="Horizontal">
<TextBlock Text="Option 3: " />
<TextBox Width="200" IsEnabled="{Binding IsChecked, ElementName=op3}" />
</StackPanel>
</RadioButton.Content>
</RadioButton>
<RadioButton Name="op4" GroupName="A" Margin="2">
<RadioButton.Content>
<StackPanel Orientation="Horizontal">
<TextBlock Text="Option 4: " />
<TextBox Width="200" IsEnabled="{Binding IsChecked, ElementName=op4}" />
</StackPanel>
</RadioButton.Content>
</RadioButton>
<RadioButton Name="op5" GroupName="A" Margin="2">
<RadioButton.Content>
<StackPanel Orientation="Horizontal">
<TextBlock Text="Option 5: " />
<TextBox Width="200" IsEnabled="{Binding IsChecked, ElementName=op5}" />
</StackPanel>
</RadioButton.Content>
</RadioButton>
</StackPanel>