2012-02-04 24 views
0

以下のXAMLを使用してチェックボックスを作成しましたが、何らかの理由でマウスがコントロール上を移動したときに背景色を変更できません。ストーリーボードは不透明度を設定するために機能しますが、背景色は変更されません。私が間違って何をしているのか?ボーダーアニメーションは色を変更しません。

<Style x:Key="{x:Type CheckBox}" TargetType="CheckBox"> 
    <Setter Property="SnapsToDevicePixels" Value="true"/> 
    <Setter Property="OverridesDefaultStyle" Value="true"/> 
    <Setter Property="FocusVisualStyle" Value="{DynamicResource CheckBoxFocusVisual}" /> 
    <Setter Property="Foreground" Value="{StaticResource FGBrush}"/> 
    <Setter Property="HorizontalContentAlignment" Value="Stretch"/> 
    <Setter Property="VerticalContentAlignment" Value="Stretch"/> 
    <Setter Property="RenderOptions.EdgeMode" Value="Aliased"/> 
    <Setter Property="Template"> 
     <Setter.Value> 
      <ControlTemplate TargetType="CheckBox"> 
       <BulletDecorator Background="Transparent" Height="20" MinHeight="{DynamicResource ResourceKey=MinimumIteractSizeDips}"> 
        <BulletDecorator.Bullet> 
         <Grid MinHeight="{DynamicResource ResourceKey=MinimumIteractSizeDips}" 
           MinWidth="{DynamicResource ResourceKey=MinimumIteractSizeDips}" 
           Width="20" 
           Height="20" 
           SnapsToDevicePixels="True" RenderOptions.EdgeMode="Aliased" > 

          <Border x:Name="Border" 
            BitmapEffect="{StaticResource DropShadow}" 
            CornerRadius="0" 
            Background="{StaticResource ControlGradientBrush}" 
            BorderThickness="1" 
            BorderBrush="{StaticResource NormalBorderBrush}" RenderOptions.EdgeMode="Aliased" 
           MinHeight="{DynamicResource ResourceKey=MinimumIteractSizeDips}" 
           MinWidth="{DynamicResource ResourceKey=MinimumIteractSizeDips}" 
           Width="20" 
           Height="20" > 

           <Viewbox Stretch="UniformToFill" Margin="2" > 
            <Path 
            x:Name="CheckMark" 
            SnapsToDevicePixels="True" 
            Stroke="{StaticResource GlyphBrush}" 
            StrokeThickness="7" 
            RenderOptions.EdgeMode="Aliased" 
            Data="M 2 2 L 17 17 M 2 17 L 17 2" HorizontalAlignment="Center" VerticalAlignment="Center"/> 
           </Viewbox> 

          </Border> 
         </Grid> 
        </BulletDecorator.Bullet> 
        <ContentPresenter Margin="4,0,0,0" 
          VerticalAlignment="Top" 
          HorizontalAlignment="Left" 
          RecognizesAccessKey="True"/> 
       </BulletDecorator> 
       <ControlTemplate.Triggers> 
        <Trigger Property="IsChecked" Value="false"> 
         <Setter TargetName="CheckMark" Property="Visibility" Value="Collapsed"/> 
        </Trigger> 
        <Trigger Property="IsChecked" Value="{x:Null}"> 
         <Setter TargetName="CheckMark" Property="Data" Value="M 0 7 L 7 0" /> 
        </Trigger> 
        <Trigger Property="IsMouseOver" Value="true"> 
         <Trigger.EnterActions> 
          <BeginStoryboard Name="HighlightAnim"> 
           <!--<Storyboard TargetName="Border" TargetProperty="Opacity" > 
            <DoubleAnimation To="0.5" Duration="00:00:00.1"/> 
           </Storyboard>--> 
           <Storyboard TargetName="Border"> 
            <ColorAnimation Duration="0:0:0.15" 
              Storyboard.TargetName="Border" 
              Storyboard.TargetProperty="(Border.Background).(SolidColorBrush.Color)" 
              To="Red" /> 
           </Storyboard> 
          </BeginStoryboard> 
         </Trigger.EnterActions> 
         <Trigger.ExitActions> 
          <StopStoryboard BeginStoryboardName="HighlightAnim"/> 
         </Trigger.ExitActions> 
        </Trigger> 
        <Trigger Property="IsPressed" Value="true"> 
         <Setter TargetName="Border" Property="Background" Value="{StaticResource PressedBrush}" /> 
         <Setter TargetName="Border" Property="BorderBrush" Value="{StaticResource PressedBorderBrush}" /> 
        </Trigger> 
        <Trigger Property="IsEnabled" Value="false"> 
         <Setter TargetName="Border" Property="Background" Value="{StaticResource DisabledBackgroundBrush}" /> 
         <Setter TargetName="Border" Property="BorderBrush" Value="{StaticResource DisabledBorderBrush}" /> 
         <Setter Property="Foreground" Value="{StaticResource DisabledForegroundBrush}"/> 
        </Trigger> 
       </ControlTemplate.Triggers> 
      </ControlTemplate> 
     </Setter.Value> 
    </Setter> 
</Style> 
+0

正確には何が起こっているのですか?コードを使ってリソースを除いて試したときに動作します。 –

+0

@マークホール私のアプリケーションで色が変わらないと奇妙に思えますが、私は楕円で全く同じことを試しましたが、色も変わりません。ストーリーボードを取り出してプロパティを変更するだけで動作します。 – user1145533

答えて

0

アニメーションは、SolidColorBrushの「カラー」プロパティを変更しようとします。ただし、「Border」要素には、ControlGradientBrushリソースに「Background」プロパティが設定されています。私はグラデーションブラシのグラデーションストップをアニメーション化するか、ボーダーの背景を同様のSolidColorBrushに設定する必要があると思います。

関連する問題