Question

As the title says, I would like the first nested Button to be selected (this button selects a view) when the tab item is clicked. Here is my code below:

      <TabItem Header="Scheduling">
            <StackPanel Style="{StaticResource ResourceKey=TabStackPanelStyle}">
                <RadioButton Command="{Binding BookResourceCommand}" Style="{StaticResource ResourceKey=TabButtonStyle}">Book</RadioButton>
                <RadioButton Command="{Binding NewResourceCommand}" Style="{StaticResource ResourceKey=TabButtonStyle}">New</RadioButton>
                <RadioButton Command="{Binding EditResourceCommand}" Style="{StaticResource ResourceKey=TabButtonStyle}">Edit</RadioButton>
                <RadioButton Command="{Binding DeleteResourceCommand}" Style="{StaticResource ResourceKey=TabButtonStyle}">Delete</RadioButton>
            </StackPanel>
        </TabItem>

This TabItem sits in a TabControl with a few more similar TabItems. All I want to do is have the TabItem select the first RadioButton (by default) when it is clicked. These radio buttons change a user control in my ViewModel.

I know it would be possible using EventTriggers associated with the TabItem but there must be a better way.

Thanks!

Was it helpful?

Solution

I think in this situation you can use Binding:

TabItem

<TabItem x:Name="MyTabItem" Header="Two">
    <Label Content="Some Content" />
</TabItem>

RadioButton

<RadioButton Name="MyButton" Content="Two" IsChecked="{Binding ElementName=MyTabItem, Path=IsSelected}" />

If you want to be when you click on the RadioButton, the tab is not selected, use Mode=OneWay:

<RadioButton Name="MyButton" IsChecked="{Binding ElementName=MyTabItem, Path=IsSelected, Mode=OneWay}" />
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top