XAML样式用于闪烁

时间:2011-10-10 13:02:41

标签: .net wpf xaml

我为按钮创建样式:

<Style TargetType="{x:Type Button}">
        <Setter Property="Background" Value="#8A88E1"/>
        <Setter Property="Width" Value="40" />
        <Setter Property="Margin" Value="10" />
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="Button">
                    <Grid>
                        <Ellipse Fill="{TemplateBinding Background}"/>
                        <ContentPresenter HorizontalAlignment="Center"
                        VerticalAlignment="Center"/>
                    </Grid>
                    <ControlTemplate.Triggers>
                        <Trigger Property="IsMouseOver" Value="True">
                            <Setter Property="Background" Value="#ff0000"/>                    
                        </Trigger>
                    </ControlTemplate.Triggers>
                </ControlTemplate>
            </Setter.Value>
        </Setter>

    </Style>

一切都好。现在我想创建一种在悬停按钮时被迫闪烁的样式。

1 个答案:

答案 0 :(得分:1)

使用触发器和故事板,这是一种方法:

    <Style.Triggers>
        <Trigger Property="IsMouseOver" Value="True">
            <Trigger.EnterActions>
                <BeginStoryboard>
                    <Storyboard>
                        <ColorAnimation Storyboard.TargetProperty="Background.Color" Duration="0:0:0.2"
                            From="White" To="Red" RepeatBehavior="3x" AutoReverse="True"/>
                    </Storyboard>
                </BeginStoryboard>
            </Trigger.EnterActions>
        </Trigger>
    </Style.Triggers>