<Window.Resources>
<!-- TabItem的样式 -->
<Style TargetType="{x:Type TabItem}">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type TabItem}">
<Grid>
<!-- 主Border -->
<Border
Name="bd"
Margin="5,10,5,0"
Background="{TemplateBinding Background}"
BorderBrush="Gray"
BorderThickness="3"
CornerRadius="7">
<ContentPresenter
Margin="20,10"
VerticalAlignment="Center"
ContentSource="Header" />
</Border>
</Grid>
<ControlTemplate.Triggers>
<Trigger Property="IsSelected" Value="True">
<Setter TargetName="bd" Property="BorderThickness" Value="2" />
<Setter TargetName="bd" Property="Margin" Value="0" />
</Trigger>
<Trigger Property="IsMouseOver" Value="True" />
</ControlTemplate.Triggers>
</ControlTemplate>
</Setter.Value>
</Setter>
<Setter Property="Foreground" Value="Black" />
<Setter Property="FontSize" Value="18" />
</Style>
<!-- TabControl的样式 -->
<Style TargetType="{x:Type TabControl}">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type TabControl}">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition Height="*" />
</Grid.RowDefinitions>
<Border Padding="10">
<TabPanel IsItemsHost="True" />
</Border>
<Border
Grid.Row="1"
Padding="10"
BorderBrush="Gray"
BorderThickness="2">
<ContentPresenter Name="PART_SelectedContentHost" ContentSource="SelectedContent" />
</Border>
</Grid>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
</Window.Resources>
<TabControl>
<TabItem Background="#FFFFFF72" Header="aaa">test</TabItem>
<TabItem Background="#FFAEFF7A" Header="bbb">
<DockPanel>
<Button DockPanel.Dock="Bottom">hehe</Button>
<TextBox />
</DockPanel>
</TabItem>
<TabItem Background="#FFA6D5FF" Header="ccc">test</TabItem>
</TabControl>
WPF TabControl美化
内容版权声明:除非注明,否则皆为本站原创文章。