我在按钮视觉状态管理器中的情节提要有一个奇怪的问题。我有两个样式相同的按钮和一个特定的Foreground
. 即Path
按钮的内容将其Fill
属性绑定到此前景。
<Button Style="{DynamicResource ButtonStyleListNavigation}"
Foreground="{DynamicResource NavigationButtonForegroundBrush}">
<Button.Content>
<Path Data="{StaticResource LeftArrowPath}"
Fill="{Binding RelativeSource=
{RelativeSource Mode=FindAncestor, AncestorType=Button},
Path=Foreground}" />
</Button.Content>
</Button>
<Button Style="{DynamicResource ButtonStyleListNavigation}"
Foreground="{DynamicResource NavigationButtonForegroundBrush}">
<Button.Content>
<Path Data="{StaticResource RightArrowPath}"
Fill="{Binding RelativeSource=
{RelativeSource Mode=FindAncestor, AncestorType=Button},
Path=Foreground}" />
</Button.Content>
</Button>
在正常状态下,按钮如下所示:
样式ButtonStyleListNavigation
如下:
<Style x:Key="ButtonStyleListNavigation" TargetType="Button">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="Button">
<Border>
<VisualStateManager.VisualStateGroups>
<VisualStateGroup x:Name="CommonStates">
<VisualState x:Name="Normal"/>
<VisualState x:Name="MouseOver">
<Storyboard>
<ColorAnimationUsingKeyFrames
Storyboard.TargetProperty=
"(Control.Foreground).(SolidColorBrush.Color)">
<EasingColorKeyFrame KeyTime="0" Value="Chocolate" />
</ColorAnimationUsingKeyFrames>
</Storyboard>
</VisualState>
<VisualState x:Name="Pressed" />
<VisualState x:Name="Disabled" />
</VisualStateGroup>
</VisualStateManager.VisualStateGroups>
<ContentPresenter x:Name="contentPresenter" />
</Border>
</ControlTemplate>
</Setter>
</Style>
所以当用户将鼠标悬停在一个按钮上时,它的颜色应该会改变,非常简单。但是,当我将鼠标悬停在一个按钮上时会发生以下情况:
两个按钮都会改变颜色。我显然做错了什么,但我无法弄清楚它是什么。