0
votes

I want to have my company's name on the TabControl just before the first tab-item.

I have tried to add a TextBlock directly in TabControl. But it appears as if a new TabItem without any header is added just before the first TabItem and inside that newly created TabItem I get my company's name.

Here is the code:

<TabControl>
    <TextBlock Text="MyCompanyName" />
    <TabItem Header="FirstTabITem" />
    <TabItem Header="SecondTabITem" />
</TabControl>

Is this the limitation of WPF?

3
Why would you want to do this? It's against all standards and guidelines. You can do this in WPF, but it's a lot of work and everybody using your control will be confused. - nvoigt
@nvoigt My tab Control is the root of my window. Then what is the best place to specify company name? - Khushi
I don't know, that's something you have to decide. You have to design your window. Maybe you need a different root, with your company name and logo on top and the tab control below that? Only you can decide that but note that if the technical side is problematic, it's probably not meant to be used that way. - nvoigt

3 Answers

3
votes

I believe what you're looking to do is overwrite the XAML surrounding the <TabPanel> in the default TabControl.Template. I've done this once in the past and it wasn't too bad.

If you have Blend you can easily create a copy of the TabControl.Template to modify, or you can find an example MSDN template here and work from that.

If you work from the MSDN example template, just wrap the <TabPanel> in something else such as a DockPanel, and add a <TextBlock> with your company name to it.

<Style TargetType="{x:Type TabControl}">

  ...

  <Setter Property="Template">
    <Setter.Value>
      <ControlTemplate TargetType="{x:Type TabControl}">
        <Grid KeyboardNavigation.TabNavigation="Local">
          <Grid.RowDefinitions>
            <RowDefinition Height="Auto"/>
            <RowDefinition Height="*"/>
          </Grid.RowDefinitions>
          <DockPanel Grid.Row="0">
              <TextBlock Text="Company Name" DockPanel.Dock="Left" />
              <TabPanel Name="HeaderPanel" IsItemsHost="True" ... />
          </DockPanel>

          ...

        </Grid>
      </ControlTemplate>
    </Setter.Value>
 </Style>
0
votes

Use this It might help You

        <TabItem Header="My Company Name" IsEnabled="False"/>
        <TabItem Header="FirstTabITem" />
        <TabItem Header="SecondTabITem" />
    </TabControl>
0
votes

Edit the style of first tab item as given below.

 <TabControl Margin="20">
        <TabItem IsEnabled="False" >
            <TabItem.Style>
                <Style TargetType="TabItem">
                    <Setter Property="Template">
                        <Setter.Value>
                            <ControlTemplate>
                                <TextBlock Text="My Company" Margin="0,0,5,0"/>
                            </ControlTemplate>
                        </Setter.Value>
                    </Setter>
                </Style>
            </TabItem.Style>
        </TabItem>
    <TabItem Header="FirstTabITem" IsSelected="True"/>
    <TabItem Header="SecondTabITem" />
  </TabControl>