I have 3 tab items to implement. When the program executes, I would like user to only be able to see tab1 and hide tab 2 and tab 3.
something like this happens when the program execute:
public Window1()
{
InitializeComponent();
// I need tabs 2 and 3 to be hidden
}
Then I have a button in tab 1. When users click this, tab 2 shows up but still hide tab 3
private void Button1_Click(object sender, RoutedEventArgs e)
{
tabcontrol1.SelectedIndex = 1;
//need some code to show tab 2
}
And I have a button in tab 2 to show tab 3 and then all the tabs are visible
private void Button2_Click(object sender, RoutedEventArgs e)
{
tabcontrol1.SelectedIndex = 2;
// need some code to show tab 3
}
My XAML code:
<TabControl Name="Tabcontrol1" Margin=" 5" SelectedIndex="0">
<TabItem Header="Directories">
<Grid Width="1185" Height="945" Background="White" >
<Label Height="28" HorizontalAlignment="Right"
Margin="0,0,25,0" Name="label11" VerticalAlignment="Top"
Width="120">Step 1 of 2</Label>
</Grid>
</TabItem>
<TabItem Header="Properties" Opacity="1" Name="Properties">
<Grid Width="1185" Height="945" Background="White" >
<Button Height="32" Name="Button1" VerticalAlignment="Bottom"
HorizontalAlignment="Right" Width="82" Click="Button1_Click"
Margin="0,0,41,49">Build</Button>
</Grid>
</TabItem>
<TabItem Header ="Output">
<Grid Width="1185" Height="945" Background="White">
<Button Height="32" Name="Button2" VerticalAlignment="Bottom"
HorizontalAlignment="Right" Width="82" Click="Button2_Click"
Margin="0,0,41,49">Build</Button>
</Grid>
</TabItem>
</TabControl>
I am quite confused because i can only select a tab using:
tabcontrol1.SelectedIndex = 1;
I was thinking along the line of implementing
tabcontrol1.SelectedIndex.Visibility = Hidden;
please advice thanks.
Set
Visibilityof 2nd and 3rd tab toCollapsedinitially. And also give them a name to be able to access them in code behind.And change your button click code to the following: