这是XAML代码。
当鼠标在TabItem上时,我不想要两种忧郁。
当鼠标在TabItem上时,我不想要两种忧郁。
当鼠标在TabItem上时,我不想要两种忧郁。
当鼠标在TabItem上时,我不想要两种忧郁。
<Window x:Class="MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Height="200" Width="400">
<Window.Resources>
<LinearGradientBrush x:Key="TabItemHotBackground" EndPoint="0,1" StartPoint="0,0">
<GradientStop Color="Blue" Offset="0.15"/>
<GradientStop Color="Blue" Offset=".5"/>
<GradientStop Color="Blue" Offset=".5"/>
<GradientStop Color="Blue" Offset="1"/>
</LinearGradientBrush>
<Style x:Key="TabItemStyle1" TargetType="{x:Type TabItem}">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type TabItem}">
<Grid SnapsToDevicePixels="true">
<Border x:Name="Bd" BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="1,1,1,0" Background="{TemplateBinding Background}" Padding="{TemplateBinding Padding}">
<ContentPresenter x:Name="Content" ContentSource="Header" HorizontalAlignment="{Binding HorizontalContentAlignment, RelativeSource={RelativeSource AncestorType={x:Type ItemsControl}}}" RecognizesAccessKey="True" SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" VerticalAlignment="{Binding VerticalContentAlignment, RelativeSource={RelativeSource AncestorType={x:Type ItemsControl}}}"/>
</Border>
</Grid>
<ControlTemplate.Triggers>
<Trigger Property="IsMouseOver" Value="true">
<Setter Property="Background" TargetName="Bd" Value="{StaticResource TabItemHotBackground}"/>
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
</Window.Resources>
<Grid>
<TabControl Background="Pink">
<TabItem Background="Yellow" Style="{DynamicResource TabItemStyle1}">
<TabItem.Header>
<StackPanel>
<TextBlock Text="Customer" HorizontalAlignment="Center"/>
<TextBlock Text="Name" HorizontalAlignment="Center"/>
</StackPanel>
</TabItem.Header>
</TabItem>
<TabItem Background="Yellow" Style="{DynamicResource TabItemStyle1}">
<TabItem.Header>
<StackPanel>
<TextBlock Text="Customer" HorizontalAlignment="Center"/>
<TextBlock Text="Address" HorizontalAlignment="Center"/>
</StackPanel>
</TabItem.Header>
</TabItem>
</TabControl>
</Grid>
</Window>问题:

所以,当鼠标在TabItem上时,我不想有两个忧郁。
发布于 2018-02-25 18:41:02
更改TabItem模板的最简单方法是编辑TabItem模板,右键单击vs designer EditTemplate > edit副本中的TabItem,然后查找带有TabItem.MouseOver.Background键的LinearGradientBrush,或者用您的颜色将其更改为SolidColorBrush (并保留相同的键):
<SolidColorBrush x:Key="TabItem.MouseOver.Background" Color="Blue"/>或者更新GradiantStop点以使用相同的颜色:
<LinearGradientBrush x:Key="TabItem.MouseOver.Background" EndPoint="0,1" StartPoint="0,0">
<GradientStop Color="Blue" Offset="0.0"/>
<GradientStop Color="Blue" Offset="1.0"/>
</LinearGradientBrush>https://stackoverflow.com/questions/48976652
复制相似问题