Marek M.
Marek M.

Reputation: 3951

Item template for TabControl

I'm using TabControl to present data from different DataTables. With this XAML code:

<TabControl Margin="5, 5, 5, 5" 
            HorizontalAlignment="Stretch" 
            DockPanel.Dock="Top"
            ItemsSource="{Binding Path=ItemInfoViewModels}">
    <TabControl.ItemTemplate>
        <DataTemplate>
            <StackPanel>
            <TextBlock Text="{Binding EditingTable.Name}"></TextBlock>
            <ContentControl>
                    <Partials:ItemInfo />
                </ContentControl>
            </StackPanel>
        </DataTemplate>
    </TabControl.ItemTemplate>
</TabControl>

I get a view that looks like this:

TabControl view

which is obviously wrong. Everything - header text and content - is displayed where normally Header would be shown. So how can I change my XAML, so that it would look as it should?

Upvotes: 0

Views: 96

Answers (1)

John Bowen
John Bowen

Reputation: 24453

Try using ContentTemplate instead of ItemTemplate. ItemTemplate is applied to the Header of each TabItem, ContentTemplate is used to display the selected tab.

You could alternatively set the ItemContainerStyle and manipulate the settings on the TabItems more directly.

Upvotes: 1

Related Questions