0

ボタンの視覚状態マネージャー内のストーリーボードに奇妙な問題があります。同じスタイルと特定の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>

したがって、ユーザーが 1 つのボタンにマウスオーバーすると、色が変化するはずです。ただし、 1 つのボタンにマウスを合わせると、次のようになります。

ボタンのマウスオーバー

両方のボタンの色が変わります。私は明らかに何か間違ったことをしていますが、それが何であるかわかりません。

4

1 に答える 1

3

Foreground両方のボタンのプロパティを同じ SolidColorBrush インスタンスに設定しています (リソースによって指定されますNavigationButtonForegroundBrush)。次に、ColorAnimationColorで、SolidColorBrush のプロパティを式で変更します(Control.Foreground).(SolidColorBrush.Color)。明らかに、両方のボタンがForeground変更されました。

ブラシをリソースとして使用せず、その色だけを使用することで、これを防ぐことができます。したがって、ボタンは次のように変わります。

<Button Style="{DynamicResource ButtonStyleListNavigation}">
  <Button.Foreground>
    <SolidColorBrush Color="{DynamicResource NavigationButtonForegroundColor}" />
  </Button.Foreground>
  <Button.Content>
    <Path Data="{StaticResource LeftArrowPath}"
          Fill="{Binding RelativeSource=
                         {RelativeSource Mode=FindAncestor, AncestorType=Button},
                         Path=Foreground}" />
  </Button.Content>
</Button>
于 2012-05-15T09:34:56.123 に答える