我已经创建了一个TabControl
,它将有两个选项卡项,我为这个TabControl
创建了一个样式。
然而,我有一个问题,当焦点在一个TabItem,没有选择的图像显示,这个TabItem
的背景将有一个蓝色。
我想删除这个蓝色的图像显示从TabItem
时,做一个重点。
我已经尝试了很多方法来做到这一点,但这些方法中的任何一个对我都有效。
<TabControl Style="{StaticResource newStyle}">
<TabItem Header="Tab 1">
<TabItem.Style>
<Style TargetType="TabItem">
<Setter Property="BorderBrush" Value="Transparent"/>
<Style.Triggers>
<Trigger Property="IsSelected" Value="true">
<Setter Property="BorderBrush" Value="Transparent"/>
</Trigger>
<Trigger Property="IsSelected" Value="false">
<Setter Property="BorderBrush" Value="Transparent"/>
</Trigger>
</Style.Triggers>
</Style>
</TabItem.Style>
</TabItem>
<TabItem Header="Tab 2">
<TabItem.Style>
<Style TargetType="TabItem">
<Setter Property="BorderBrush" Value="Transparent"/>
<Style.Triggers>
<Trigger Property="IsSelected" Value="true">
<Setter Property="BorderBrush" Value="Transparent"/>
</Trigger>
<Trigger Property="IsSelected" Value="false">
<Setter Property="BorderBrush" Value="Transparent"/>
</Trigger>
</Style.Triggers>
</Style>
</TabItem.Style>
</TabItem>
</TabControl>
新样式样式:
<Style TargetType="{x:Type TabControl}" x:Key="newStyle">
<Setter Property="Background" Value="#FFFFFFFF" />
<Setter Property="BorderThickness" Value="1" />
<Setter Property="FontFamily" Value="Trebuchet MS" />
<Setter Property="FontSize" Value="12" />
<Setter Property="Padding" Value="5" />
<Setter Property="HorizontalContentAlignment" Value="Stretch" />
<Setter Property="VerticalContentAlignment" Value="Stretch" />
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type TabControl}">
<Grid ClipToBounds="true" SnapsToDevicePixels="true" KeyboardNavigation.TabNavigation="Local">
<Grid.ColumnDefinitions>
<ColumnDefinition x:Name="ColumnDefinition0" />
<ColumnDefinition x:Name="ColumnDefinition1" Width="0" />
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="Auto" x:Name="RowDefinition0" />
<RowDefinition Height="*" x:Name="RowDefinition1" />
</Grid.RowDefinitions>
<Border Background="Transparent" CornerRadius="0,0,0,0" x:Name="border" Margin="5" Panel.ZIndex="1">
<TabPanel x:Name="HeaderPanel" IsItemsHost="true" Panel.ZIndex="1" KeyboardNavigation.TabIndex="1" Width="Auto" Height="Auto" Margin="4,0,0,0">
<!--<TabPanel.LayoutTransform>
<TransformGroup>
<ScaleTransform ScaleX="1" ScaleY="1" />
<SkewTransform AngleX="0" AngleY="0" />
<RotateTransform Angle="0" />
<TranslateTransform X="0" Y="0" />
</TransformGroup>
</TabPanel.LayoutTransform>
<TabPanel.RenderTransform>
<TransformGroup>
<ScaleTransform ScaleX="1" ScaleY="1" />
<SkewTransform AngleX="0" AngleY="0" />
<RotateTransform />
<TranslateTransform X="0" Y="0" />
</TransformGroup>
</TabPanel.RenderTransform>-->
</TabPanel>
</Border>
<Border Grid.Row="1" x:Name="ContentPanel" Background="Transparent" BorderBrush="Transparent" BorderThickness="0" >
<ContentPresenter Margin="4" x:Name="PART_SelectedContentHost" ContentSource="SelectedContent" />
</Border>
</Grid>
<ControlTemplate.Triggers>
<Trigger Property="TabStripPlacement" Value="Bottom">
<Setter Property="Grid.Row" TargetName="ContentPanel" Value="0" />
<Setter Property="Height" TargetName="RowDefinition0" Value="*" />
<Setter Property="Height" TargetName="RowDefinition1" Value="Auto" />
<Setter Property="Grid.Row" TargetName="border" Value="1" />
<Setter Property="CornerRadius" TargetName="ContentPanel" Value="2,2,0,0" />
<Setter Property="CornerRadius" TargetName="border" Value="0,0,2,2" />
<Setter Property="Margin" TargetName="HeaderPanel" Value="4,-2.5,0,0" />
<Setter Property="Margin" TargetName="border" Value="0,0,0,0" />
</Trigger>
<Trigger Property="TabStripPlacement" Value="Left">
<Setter Property="Grid.Row" TargetName="HeaderPanel" Value="0" />
<Setter Property="Grid.Row" TargetName="ContentPanel" Value="0" />
<Setter Property="Grid.Column" TargetName="ContentPanel" Value="1" />
<Setter Property="Width" TargetName="ColumnDefinition0" Value="Auto" />
<Setter Property="Width" TargetName="ColumnDefinition1" Value="*" />
<Setter Property="Height" TargetName="RowDefinition0" Value="*" />
<Setter Property="Height" TargetName="RowDefinition1" Value="0" />
<Setter Property="Grid.Column" TargetName="border" Value="0" />
<Setter Property="Margin" TargetName="border" Value="0,0,0,0" />
<Setter Property="Margin" TargetName="ContentPanel" Value="0,0,0,0" />
<Setter Property="CornerRadius" TargetName="border" Value="0,2,2,0" />
<Setter Property="CornerRadius" TargetName="ContentPanel" Value="0,2,2,0" />
<Setter Property="Margin" TargetName="HeaderPanel" Value="4,0,-2.5,0" />
</Trigger>
<Trigger Property="TabStripPlacement" Value="Right">
<Setter Property="Grid.Row" TargetName="HeaderPanel" Value="0" />
<Setter Property="Grid.Row" TargetName="ContentPanel" Value="0" />
<Setter Property="Grid.Column" TargetName="ContentPanel" Value="0" />
<Setter Property="Width" TargetName="ColumnDefinition0" Value="*" />
<Setter Property="Width" TargetName="ColumnDefinition1" Value="Auto" />
<Setter Property="Height" TargetName="RowDefinition0" Value="*" />
<Setter Property="Height" TargetName="RowDefinition1" Value="0" />
<Setter Property="Grid.Column" TargetName="border" Value="1" />
<Setter Property="CornerRadius" TargetName="ContentPanel" Value="2,0,0,2" />
<Setter Property="CornerRadius" TargetName="border" Value="0,2,2,0" />
<Setter Property="Margin" TargetName="HeaderPanel" Value="-3,0,0,0" />
</Trigger>
<Trigger Property="IsEnabled" Value="false">
<Setter Property="Foreground" Value="Transparent" />
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
1条答案
按热度按时间ubof19bj1#
为
TabItem
创建自定义模板。以下是默认模板。根据您的要求修改TabItem.MouseOver.Background
资源和/或触发器。