WPF Bind to selected Radio Button

c#, wpf

Solution

<Label Content="{Binding SelectedValue.Content, ElementName=list}"  />

<ListBox x:Name="list" SelectedIndex="1"  >
    <ListBox.ItemContainerStyle>
        <Style TargetType="ListBoxItem">
            <Setter Property="Template">
                <Setter.Value>
                    <ControlTemplate TargetType="ListBoxItem" >
                        <RadioButton GroupName="a" Content="{TemplateBinding Content}" IsChecked="{Binding IsSelected, RelativeSource={RelativeSource TemplatedParent}  }"  />
                    </ControlTemplate>
                </Setter.Value>
            </Setter>
        </Style>
    </ListBox.ItemContainerStyle>
    <ListBoxItem>Create Graph</ListBoxItem>
    <ListBoxItem>Create Map</ListBoxItem>
</ListBox>

I think you can make it shorter than what I did.

Problem

I have a Radiobutton group: ``` <RadioButton Name="_CreateGraph" GroupName="MapOrGraph" Content="Create Graph" /> <RadioButton Name="_CreateMap" GroupName="MapOrGraph" Content="Create Map" /> ``` How do I bind the content of a label to the selected radio button's content? e.g. the label should say Create Graph or Create Map depending on which radio box is created?

Original source

Related problems