You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

86 lines
5.0 KiB

<TabItem x:Class="SchedulingSystemClient.UserControls.UC_TabItemWithClose"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Loaded="TabItem_Loaded">
<!--定义资源-->
<TabItem.Resources>
<!--按钮样式:用x:Key设置唯一键-->
<Style x:Key="CloseButtonStyle" TargetType="{x:Type Button}">
<!--边框:黑色-->
<Setter Property="BorderBrush" Value="White"></Setter>
<!--背景:白色-->
<Setter Property="Background" Value="#cccccc"></Setter>
<Setter Property="Template">
<Setter.Value>
<!--自定义模板-->
<ControlTemplate TargetType="{x:Type Button}">
<!--定义视觉树-->
<Grid>
<!--形状绘图:椭圆-->
<!-- 模板绑定(TemplateBinding):使用TemplateBinding扩展把TabItem的Stroke设置为控件的Stroke。-->
<!--<Ellipse Width="20" Height="20" HorizontalAlignment="Center" VerticalAlignment="Center" Stroke="{TemplateBinding BorderBrush}" Fill="{TemplateBinding Background}" ></Ellipse>-->
<TextBlock x:Name="text" FontSize="18" Text="×" HorizontalAlignment="Center" VerticalAlignment="Center" Foreground="#000000" Margin="0,0,8,0" Padding="10,0"></TextBlock>
</Grid>
<!--定义触发器-->
<ControlTemplate.Triggers>
<Trigger Property="IsPressed" Value="true">
<!--设置背景色-->
<Setter Property="Background" Value="White"></Setter>
<!--设置字体颜色:白色-->
<Setter TargetName="text" Property="Foreground" Value="#000000"></Setter>
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
</TabItem.Resources>
<!--定义样式-->
<TabItem.Style>
<!--选项卡-->
<Style TargetType="{x:Type TabItem}">
<!--边框画刷:黑色-->
<Setter Property="BorderBrush" Value="White"></Setter>
<!--背景色:白色-->
<Setter Property="Background" Value="#cccccc"></Setter>
<!--字体:黑色-->
<Setter Property="Foreground" Value="#000000"></Setter>
<!--内边距:5,0,0,0-->
<Setter Property="Padding" Value="5,0,0,0"></Setter>
<!--水平对齐方式:靠左-->
<Setter Property="HorizontalAlignment" Value="Left"></Setter>
<!--垂直对齐方式:居中-->
<Setter Property="VerticalAlignment" Value="Center"></Setter>
<Setter Property="Template">
<Setter.Value>
<!--定义模板:选项卡-->
<ControlTemplate TargetType="{x:Type TabItem}">
<!--定义视觉树-->
<!--边框:边框画刷BorderBrush,边框粗度BorderThickness,背景都是绑定模板样式Background-->
<Border CornerRadius="0,0,0,0" BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}" Background="{TemplateBinding Background}">
<Grid>
<!--定义两列-->
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*"></ColumnDefinition>
<ColumnDefinition Width="20"></ColumnDefinition>
</Grid.ColumnDefinitions>
<!--定义内容:内容演示-->
<ContentPresenter Grid.Column="0" ContentSource="Header" Margin="{TemplateBinding Padding}" HorizontalAlignment="{TemplateBinding HorizontalAlignment}" VerticalAlignment="{TemplateBinding VerticalAlignment}"/>
<!--按钮样式Style:依赖属性绑定—》资源-->
<Button Grid.Column="1" Name="btn_Close" Style="{StaticResource CloseButtonStyle}" Click="btn_Close_Click"></Button>
</Grid>
</Border>
<!--定义触发器-->
<ControlTemplate.Triggers>
<Trigger Property="IsSelected" Value="true">
<Setter Property="Background" Value="#E8E8E8"></Setter>
<Setter Property="Foreground" Value="#000000"></Setter>
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
</TabItem.Style>
</TabItem>