TabItem Storyboard affects neighboring TabItems
We have a TabItem Style which contains a very simple ControlTemplate:
<Border x:Name="border" BorderThickn开发者_如何学编程ess="0" Background="{DynamicResource MediumGray}" Margin="0,0,1,1"
SnapsToDevicePixels="True" TextBlock.Foreground="{DynamicResource DarkGray}">
<TextBlock HorizontalAlignment="Center" VerticalAlignment="Center" Text="{TemplateBinding Header}" />
</Border>
The ControlTemplate contains an EventTrigger which fires on MouseEnter. The storyboard uses a 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>
The Storyboard works as expected - except that it also affects the other TabItems in the TabControl. They all animate to the target color.
Moving the original background brush in to a ControlTemplate Resource cleared this issue:
<ControlTemplate TargetType="{x:Type TabItem}">
<ControlTemplate.Resources>
<SolidColorBrush x:Key="borderBackground" Color="{StaticResource _MediumGray}" />
</ControlTemplate.Resources>
<Border Background="{StaticResource borderBackground}" ... />
</ControlTemplate>
精彩评论