none
Changing default Tab in a TabControl in WPF RRS feed

  • Question

  • How would I go about changing the default Tab in a TabControl in WPF so that when the control comes up, the second tab is active instead of the first one on the far left?
    Web Master and Programmer
    Monday, June 9, 2008 8:50 PM

Answers

  • There are a few ways to do this.

    If you want a single TabControl to do this you could do the following:
            <TabControl SelectedIndex="2">  
                <TabControl.Items> 
                    <TabItem>One</TabItem> 
                    <TabItem>Two</TabItem> 
                    <TabItem>Three</TabItem> 
                </TabControl.Items> 
            </TabControl> 

    On the other hand if you want all your TabControls to do the same you could place this in your resources somewhere:
                <Style TargetType="TabControl">  
                    <Setter Property="SelectedIndex" Value="2"/>  
                </Style> 
    • Marked as answer by Bill_Thompson Monday, June 9, 2008 11:10 PM
    • Edited by Bruno Wouters Monday, June 9, 2008 11:11 PM fixed something
    Monday, June 9, 2008 11:08 PM

All replies

  • There are a few ways to do this.

    If you want a single TabControl to do this you could do the following:
            <TabControl SelectedIndex="2">  
                <TabControl.Items> 
                    <TabItem>One</TabItem> 
                    <TabItem>Two</TabItem> 
                    <TabItem>Three</TabItem> 
                </TabControl.Items> 
            </TabControl> 

    On the other hand if you want all your TabControls to do the same you could place this in your resources somewhere:
                <Style TargetType="TabControl">  
                    <Setter Property="SelectedIndex" Value="2"/>  
                </Style> 
    • Marked as answer by Bill_Thompson Monday, June 9, 2008 11:10 PM
    • Edited by Bruno Wouters Monday, June 9, 2008 11:11 PM fixed something
    Monday, June 9, 2008 11:08 PM
  • WPF XAML allows the IsSelected property to be set for an individual TabItem, which is sometimes more readable/portable:

    <TabControl>  
        <TabItem>One</TabItem> 
        <TabItem IsSelected="True">Two</TabItem> 
        <TabItem>Three</TabItem> 
    </TabControl> 

    Thursday, August 15, 2019 7:55 PM