wpf 中Button 边框闪烁

来源:互联网 发布:其孰能讥之乎的其 编辑:程序博客网 时间:2024/06/04 17:51

          初学WPF,还有好多东西弄不懂,有些东西学的还很混乱。工作中需要一个可以闪烁的BUTTON,看上去挺简单的,做出来也很简单,但是实现的过程对我来说还是有点艰难。

 <Style TargetType="Button">
           
            <Style.Triggers>
                <DataTrigger Binding="{Binding Test}" Value="0">
                    <DataTrigger.EnterActions>
                        <BeginStoryboard Name="borderChangStoryboard">                        
                            <Storyboard>
                                <ColorAnimation Storyboard.TargetProperty="BorderBrush.Color" From="Red" To="Pink" AutoReverse="True" RepeatBehavior="Forever"></ColorAnimation>
                            </Storyboard>                        
                        </BeginStoryboard>                    
                    </DataTrigger.EnterActions>                
                    <DataTrigger.ExitActions>
                        <StopStoryboard BeginStoryboardName="borderChangStoryboard"></StopStoryboard>             
                    </DataTrigger.ExitActions>
                </DataTrigger>
            </Style.Triggers>
        </Style>

这个Style的设计是使用了DataTrigger,其中动画的部分稍有难度:

选择ColorAnimation与DoubleAnimation?

    开始使用了DoubleAnimation,想用opacity控制变化,但是Storyboard.TargetName属性设置会出错,所幸就放弃了。

  然后使用ColorAnimation,但还是有错,错误原因“colorAnimation动画对象不能用于动画属性BorderBrush”,上网查了下,Storyboard.TargetProperty="BorderBrush"改为Storyboard.TargetProperty="BorderBrush.Color",成功了!

0 0
原创粉丝点击