Callum Watkins
Callum Watkins

Reputation: 2991

How to change TabControl selected tab

I have a TabControl on a window which has three tabs in total. I would like to select the first tab programmatically. I've tried TabControlMain.SelectedItem = 0, but this doesn't work. How can I do this?

<TabControl x:Name="TabControlMain">
    <TabItem x:Name="TabItemA" Header="A">
        ...
    </TabItem>
    <TabItem x:Name="TabItemB" Header="B">
        ...
    </TabItem>
    <TabItem x:Name="TabItemC" Header="C">
        ...
    </TabItem>
</TabControl>

Upvotes: 1

Views: 2436

Answers (1)

Stefan Wuebbe
Stefan Wuebbe

Reputation: 2149

You can set TabControl.SelectedIndex = 0 (docs)

Or set YourDesiredTabItem.IsSelected = true (docs)

TabControl.SelectedItem can only be a TabItem object or null (docs).

Upvotes: 4

Related Questions