我正在为tabitem创建一个自定义样式,并且几乎完全符合我的要求,我只剩下一个小问题。这就是控件的呈现方式:
我想要的是主要颜色是连续的,黑色边框围绕标签和内容的边缘。现在黑色边框是正确的,但有一条微弱的白色/灰色线仍然将标签与内容分开,对于我的生活,我不知道它来自哪里。
它似乎是内容边界上的一种内在的光芒,但我不知道为什么会出现这种情况。我已经在混合中打开了模板,据我所知,它只是主机的边界。当我创建另一个边框(红色区域)时,我看不到光晕。
我还尝试让活动标签右边有-2个边距而不是-1。这将删除(覆盖)白线,但黑色边框有2个额外的像素伸出而不是与内容边框完全合并。
以下是内部窗口代码的相关部分:
<Window.Resources>
<ResourceDictionary>
<SolidColorBrush Color="#FF4678A5" x:Key="br_Blue1" />
<SolidColorBrush Color="#FF3C678E" x:Key="br_Blue2" />
<SolidColorBrush Color="#FF325676" x:Key="br_Blue3" />
<SolidColorBrush Color="#FF28455F" x:Key="br_Blue4" />
<SolidColorBrush Color="#FF1E3447" x:Key="br_Blue5" />
<SolidColorBrush Color="#FF142330" x:Key="br_Blue6" />
<SolidColorBrush x:Key="br_DialogBase" Color="#FFF0F0F0" />
<Style TargetType="TabItem">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="TabItem">
<StackPanel SnapsToDevicePixels="True">
<Border Background="{TemplateBinding Background}" SnapsToDevicePixels="True" Margin="20,0,0,-1" Padding="{TemplateBinding Padding}" BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="1,1,0,1">
<ContentPresenter VerticalAlignment="Center" HorizontalAlignment="Center" SnapsToDevicePixels="True" ContentSource="Header" />
</Border>
</StackPanel>
<ControlTemplate.Triggers>
<Trigger Property="IsSelected" Value="True">
<Setter Property="Margin" Value="-10,0,-1,-1" />
<Setter Property="Padding" Value="25,15,15,15" />
<Setter Property="Foreground" Value="White" />
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</Setter.Value>
</Setter>
<Setter Property="Foreground" Value="LightGray" />
<Setter Property="BorderBrush" Value="Black" />
<Setter Property="Padding" Value="15" />
</Style>
</ResourceDictionary>
</Window.Resources>
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="*" />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
</Grid.RowDefinitions>
<TabControl TabStripPlacement="Left" Padding="0" BorderBrush="Black" BorderThickness="1">
<TabItem Background="{StaticResource br_Blue6}" Header="Test6">
<Border Background="{StaticResource br_Blue6}" />
</TabItem>
<TabItem Background="{StaticResource br_Blue5}" Header="Test5" />
<TabItem Background="{StaticResource br_Blue4}" Header="Test4" />
<TabItem Background="{StaticResource br_Blue3}" Header="Test3" />
<TabItem Background="{StaticResource br_Blue2}" Header="Test2" />
<TabItem Background="{StaticResource br_Blue1}" Header="Test1">
<Grid Background="{StaticResource br_Blue1}">
<Border BorderBrush="Black" Background="DarkRed" Margin="20" BorderThickness="1" />
</Grid>
</TabItem>
</TabControl>
</Grid>