我们有一个TabItem样式,它包含一个非常简单的ControlTemplate:
<Border x:Name="border" BorderThickness="0" Background="{DynamicResource MediumGray}" Margin="0,0,1,1"
SnapsToDevicePixels="True" TextBlock.Foreground="{DynamicResource DarkGray}">
<TextBlock HorizontalAlignment="Center" VerticalAlignment="Center" Text="{TemplateBinding Header}" />
</Border>
ControlTemplate包含一个在MouseEnter上触发的EventTrigger。故事板使用ColorAnimation:
<Storyboard>
<ColorAnimation To="{StaticResource _LightGray}" BeginTime="0:00:00"
Duration="0:00:00.200"
Storyboard.TargetName="border"
Storyboard.TargetProperty="(Border.Background).(SolidColorBrush.Color)" />
</Storyboard>
故事板按预期工作 - 除了它还影响TabControl中的其他TabItems。它们都以目标颜色为动画。
答案 0 :(得分:0)
将原始背景画笔移动到ControlTemplate资源中清除了此问题:
<ControlTemplate TargetType="{x:Type TabItem}">
<ControlTemplate.Resources>
<SolidColorBrush x:Key="borderBackground" Color="{StaticResource _MediumGray}" />
</ControlTemplate.Resources>
<Border Background="{StaticResource borderBackground}" ... />
</ControlTemplate>