Reputation: 1051
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?
Upvotes: 0
Views: 914
Reputation: 404
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>
Upvotes: 0
Reputation: 132568
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>
Upvotes: 3
Reputation: 1036
Use this It might help You
<TabItem Header="My Company Name" IsEnabled="False"/>
<TabItem Header="FirstTabITem" />
<TabItem Header="SecondTabITem" />
</TabControl>
Upvotes: 0