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

  • SEARCH
  • Home
  • 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 7720161
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T03:35:39+00:00 2026-06-01T03:35:39+00:00

I have a TabControl in my XAML which is just an empty control as

  • 0

I have a TabControl in my XAML which is just an empty control as the TabItems are dynamically generated at runtime.

My problem is I want to have the tab title and an image (a “settings” image) in the Header but I’m not sure how to go about this. As I said, I’m generating the TabItems on the fly so how and where would a template to do this fit in and where would I put it etc? Would a TabItem header template apply to TabItem controls created dynamically? (I am assuming/hoping so!)

I’ve googled and searched around here but no-one quite seems to be doing what I’m doing… just wondering if someone could give me some guidance.

<Grid Name="MainGrid" Background="#333333" ShowGridLines="False" >
    <Grid.RowDefinitions>
        <RowDefinition Height="50"/>
        <RowDefinition Height="*"/>
    </Grid.RowDefinitions>
    <Grid Grid.Row="0" ToolTip="Settings">
        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="*"/>
            <ColumnDefinition Width="*"/>
        </Grid.ColumnDefinitions>
        <TextBlock Grid.Column="0" Text="RoboNews" Foreground="SkyBlue" FontSize="32" Padding="5"/>
        <Button Name="btnSettings" Background="Transparent" Grid.Column="1" BorderBrush="#333333" BorderThickness="0" HorizontalAlignment="Right" 
                Click="btnSettings_Click" ToolTip="Click for menu">
            <!--<Image Source="Images/Settings48x48.png"/>-->
            <Image Source="/Images/MenuOpen.png" Width="36" />
        </Button>

    </Grid>

    <TabControl Name="tabCategories" Grid.Row="1" Background="Black" SelectionChanged="tabCategories_SelectionChanged">  

    </TabControl>
</Grid>
  • 1 1 Answer
  • 0 Views
  • 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-06-01T03:35:40+00:00Added an answer on June 1, 2026 at 3:35 am

    You can create a UserControl for your header

    <UserControl DataContext="{Binding RelativeSource={RelativeSource Self}}" x:Class="TabControlHeader.TabItemHeader"
                 xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
                 xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
                 xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
                 xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
                 mc:Ignorable="d" Width="Auto" Height="Auto">
        <Grid >
            <StackPanel>
                <Image Source="{Binding ImageSource}"></Image>
                <TextBlock Text="{Binding Text}"></TextBlock>
            </StackPanel>
        </Grid>
    </UserControl>
    

    With ideally DPs defined in its ViewModel, but for the time being, in code behind:

    public string ImageSource
    {
        get { return (string)GetValue(ImageSourceProperty); }
        set { SetValue(ImageSourceProperty, value); }
    }
    
    // Using a DependencyProperty as the backing store for ImageSource.  This enables animation, styling, binding, etc...
    public static readonly DependencyProperty ImageSourceProperty =
        DependencyProperty.Register("ImageSource", typeof(string), typeof(TabItemHeader));
    
    
    
    public string Text
    {
        get { return (string)GetValue(TextProperty); }
        set { SetValue(TextProperty, value); }
    }
    
    // Using a DependencyProperty as the backing store for Text.  This enables animation, styling, binding, etc...
    public static readonly DependencyProperty TextProperty =
        DependencyProperty.Register("Text", typeof(string), typeof(TabItemHeader));
    

    Then while creating your TabItem you need to set its HeaderTemplate:

    TabItem tabItem = new TabItem();
    tabItem.Height = 100;
    tabItem.Width = 50;
    var header = new FrameworkElementFactory(typeof(TabItemHeader));
    header.SetValue(TabItemHeader.TextProperty, "This is Text");
    header.SetValue(TabItemHeader.ImageSourceProperty, "This is Image uri");
    header.SetValue(TabItemHeader.HeightProperty, (double)50);
    header.SetValue(TabItemHeader.WidthProperty, (double)50);
    
    
    tabItem.HeaderTemplate = new DataTemplate { VisualTree = header };            
    tabCategories.Items.Add(tabItem);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a WinForms TabControl that I am dynamically adding TabPages to at runtime.
I have the following xaml which resides in a wpf user control - <Grid>
I have a WPF window with a tab control, and I'm defining the TabItems
i need to create types of Tabitems to my tabcontrol. each tab will have
I have TabControl. I added it to tabpages. To one of them(tpTags) I dynamically
I have a TabControl within a TabControl. I want the outer TabControl to show
I have a WPF TabControl with two TabItems. Each TabItem contains a ListBox with
I have a form with a tabcontrol and 4 tabs. I want to open
I have a WPF Menu and a Tab control. I would like the list
I have a TabControl with two TabItem s and a ListBox which is common

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.