Question

I have two groups of radio button in my WPF xaml.

<StackPanel Margin="5,-4,0,5">
 <RadioButton Content="abc" GroupName="grp1" IsChecked="true" Margin=" 8,-4,8,5"/>
 <RadioButton Content="def" GroupName="grp1" IsChecked="false" Margin=" 8,-4,8,5"/>
</StackPanel>


<StackPanel Margin="5,-4,0,5">
 <RadioButton Content="{Binding ElementName}" GroupName="grp2" IsChecked="true" Margin=" 8,-4,8,5"/>
 <RadioButton Content="xyz" GroupName="grp2" IsChecked="false" Margin=" 8,-4,8,5"/>                         
</StackPanel>

I want to bind the content of grp2 radiobutton with SelectedName in grp1 radiobuttons. For eg: if abc radiobutton is selected in grp1, then name of first radiobutton should be Value_*, where * is abc or def depending on the radio button selected.

Thanks, Rohit.

Was it helpful?

Solution

Did you mean something like this?

<StackPanel Margin="5,-4,0,5">
        <RadioButton Content="abc" GroupName="grp1" x:Name="AbcRadioBtn" IsChecked="true" Margin=" 8,-4,8,5"/>
        <RadioButton Content="def" GroupName="grp1" x:Name="DefRadioBtn" IsChecked="false" Margin=" 8,-4,8,5"/>
</StackPanel>
<StackPanel Margin="5,-4,0,5">
        <RadioButton GroupName="grp2" IsChecked="true" Margin=" 8,-4,8,5">
            <RadioButton.Style>
                <Style TargetType="RadioButton">
                    <Style.Triggers>
                        <DataTrigger Binding="{Binding ElementName=AbcRadioBtn, Path=IsChecked}" Value="True
                                     ">
                            <Setter Property="Content" Value="{Binding ElementName=AbcRadioBtn,Path=Content}"></Setter>
                        </DataTrigger>

                        <DataTrigger Binding="{Binding ElementName=DefRadioBtn, Path=IsChecked}" Value="True">
                            <Setter Property="Content" Value="{Binding ElementName=DefRadioBtn,Path=Content}"></Setter>
                        </DataTrigger>
                    </Style.Triggers>
                </Style>
            </RadioButton.Style>
        </RadioButton>
        <RadioButton Content="xyz" GroupName="grp2" IsChecked="false" Margin=" 8,-4,8,5"/>
</StackPanel>

OTHER TIPS

Bind both to a DependencyProperty in your ViewModel.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top