Custom ControlTemplate for a TabControl
Currently, in my one of my Views, I have the following TabControl setup:
<TabControl ItemsSource="{Binding Workspaces}"
ItemTemplate="{StaticResource WorkspaceTemplate}"
IsSynchronizedWithCurrentItem="True" Background="{x:Null}">
I would like to change the look and feel of the TabControl completely by setting up the ControlTemplate property. My plan is to have none of the other tabs visible and only have the conte开发者_开发问答nts of the current tab visible with no trace of the TabControl anywhere but still allowing user to Ctrl+Tab to other tabs.
Frankly speaking, I have no idea where to start. I tried adding a ContentPresenter to the TabControl's ControlTemplate but I can't figure out how to bind it to the currently active tab (note, not the actual tab but the TabItem's contents).
Any help or perhaps some boilerplate code to get me started? Perhaps there's a more suitable control out there (even if it means I'll have to lose the Ctrl+Tab functionality).
You can just create your own ControlTemplate.
<ControlTemplate TargetType="{x:Type TabItem}">
<Grid>
<Border
Name="Border"
Margin="0,0,-4,0"
Background="LightGray"
BorderBrush="Black"
BorderThickness="1,1,1,1"
Visibility="Collapsed"
CornerRadius="2,12,0,0" >
<ContentPresenter x:Name="ContentSite"
VerticalAlignment="Center"
HorizontalAlignment="Center"
ContentSource="Header"
Margin="12,2,12,2"
RecognizesAccessKey="True"/>
</Border>
</Grid>
<ControlTemplate.Triggers>
<Trigger Property="IsSelected" Value="True">
<Setter TargetName="Border" Property="Background" Value="Gray" />
<Setter TargetName="Border" Property="BorderThickness" Value="1,1,1,0" />
<Setter TargetName="Border" Property="Visibility" Value="Visible" />
</Trigger>
</ControlTemplate.Triggers>
精彩评论