Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3306906
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T21:20:38+00:00 2026-05-17T21:20:38+00:00

I just want to understand the following scenario. Where I am implementing a <TabControl>

  • 0

I just want to understand the following scenario. Where I am implementing a <TabControl> bound to a ObservableCollection<TabViewModel>

No Data Templates

When I don’t have any DataTemplates, the text WpfApplication1.TabViewModel appears in the Tab Header and Content. Ok I understand this part.

Just ItemTemplate

When I just have

<TabControl.ItemTemplate>
    <DataTemplate>
        <StackPanel Orientation="Horizontal">
            <TextBlock Text="{Binding TabTitle}" />
        </StackPanel>
    </DataTemplate>
</TabControl.ItemTemplate>

Then my tab header is filled. The tab content is still WpfApplication1.TabViewModel.

Just DataTemplate

When I just have the below in my <Window.Resources>

<DataTemplate DataType="{x:Type local:TabViewModel}">
    <TextBox Text="{Binding Text}" />
</DataTemplate>

That templates fills up the tab header.

Both

When I have both, the ItemTemplate fills up the Tab Header while the DataTemplate fills up the tab content. Why all this difference. ItemTemplate & DataTemplate fills up the tab header if the other is not present. If both are present, ItemTemplate fills up the header while DataTemplate fills the content.

Though I have things working, I am quite confused. Shouldn’t something like <TabControl.HeaderTemplate> be what fills the header and <TabControl.ItemTemplate> fill up the content?

  • 1 1 Answer
  • 1 View
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-17T21:20:39+00:00Added an answer on May 17, 2026 at 9:20 pm

    First of all, there are two templates involved here:

    • TabControl.ItemTemplate, used to render the TabItem headers
    • TabControl.ContentTemplate, used to render the TabItem contents

    If you don’t set these properties explicitly then WPF will attempt to resolve them elsewhere. It will walk up the logical tree looking for a resource telling it how to render your view model. If it finds a DataTemplate that has a matching DataType but no key, it will use it to render the view model. If it doesn’t find one, it’ll default to rendering the ToString value of the object.

    So, if you want to be explicit, you want something like this:

    <TabControl ItemsSource="{Binding Tabs}">
        <TabControl.ItemTemplate>
            <DataTemplate>
                <TextBlock Text="{Binding TabTitle}"/>
            </DataTemplate>
        </TabControl.ItemTemplate>
        <TabControl.ContentTemplate>
            <DataTemplate>
                <TextBlock Text="{Binding Text}"/>
            </DataTemplate>
        </TabControl.ContentTemplate>
    </TabControl>
    

    Since you’re not being specific, WPF is attempting to walk up your logical tree to find an appropriate DataTemplate. When it finds it, it uses it to render the view model. Where it doesn’t find it, it calls ToString and renders that.

    So to address your specific cases:

    Just ItemTemplate

    You’ve explicitly stated how to render tab headers but not tab contents. So the former is rendered using the provided DataTemplate, but the latter will default to ToString.

    Just DataTemplate

    You’ve not explicitly stated how to render either tab headers or tab contents. Therefore, WPF searches for an appropriate DataTemplate for both. Since both contain an instance of your view model (that’s their DataContext) then the same DataTemplate will be used to render tab headers and their contents.

    NOTE: you didn’t explicitly state that this is what’s happening in your question. Correct me if I’m wrong.

    Both

    In this case, you’ve explicitly stated how to render tab headers but not tab contents. Therefore, the explicit DataTemplate is used for tab headers and the implicit DataTemplate is used for tab contents.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This isn’t trully a problem, I just want to understand. Considering the following code:
I just want to make sure I understand SyncLock correctly. Given the following code
I have the following scenario: using XML Data Bindings, I have an object created
I just want to understand why I cannot create a protected enum on C#?
I understand that Silverlight 3.0 has binding but just want a simple example on
I want to understand the actual theory behind types rather than just learning about
Hopefully this one is not too hard to understand but I just want the
for some reason, the following code doesn't work. I don't understand where the issue
I have the following scenario: I have a rails web portal (Rails 3.1) and
I have a problem, I want insert data with a button click method, but

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.