边框动画不会改变颜色

时间:2012-02-04 22:49:39

标签: wpf animation border storyboard

我使用下面的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>

1 个答案:

答案 0 :(得分:0)

动画尝试更改SolidColorBrush的“Color”属性。但是,“Border”元素将“Background”属性设置为ControlGradientBrush资源。我认为您应该为渐变画笔的渐变色标设置动画,或者将边框背景设置为任何类似的SolidColorBrush。