改变使用动画不透明度WPF按钮属性 [英] Changing opacity WPF Button property using Animation

查看:626
本文介绍了改变使用动画不透明度WPF按钮属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建了阴影效果的按钮。现在我想通过在运行时改变不透明度属性添加动画此效果。但是,这code不工作:

 <按钮X:名称=btnRunCONTENT =运行点击=btn_RunEventHandler了borderThickness =1>
                        < Button.Effect>
                            &所述; DropShadowEffect颜色=红ShadowDepth =0BlurRadius =21/>
                        < /Button.Effect>
                        < Button.Triggers>
                            < EventTrigger中RoutedEvent =Button.MouseEnter>
                                < EventTrigger.Actions>
                                    < BeginStoryboard>
                                        <情节板>
                                            < D​​oubleAnimationUsingKeyFrames
                                                Storyboard.TargetProperty =(DropShadowEffect.Opacity)
                                                时长=0:0:1.6
                                                的repeatBehavior =永远>
                                                &所述; LinearDoubleKeyFrame KeyTime =0:0:0值=1/>
                                                &所述; LinearDoubleKeyFrame KeyTime =0:0:0.5值=1/>
                                                &所述; LinearDoubleKeyFrame KeyTime =0:0:0.55值=0/>
                                                &所述; LinearDoubleKeyFrame KeyTime =0:0:0.6值=1/>
                                                &所述; LinearDoubleKeyFrame KeyTime =0:0:0.7值=1/>
                                                &所述; LinearDoubleKeyFrame KeyTime =0:0:0.8值=0.6/>
                                                &所述; LinearDoubleKeyFrame KeyTime =0:0:1值=1/>
                                                < LinearDoubleKeyFrame KeyTime =0:0:1.6VALUE =1/>
                                            < / DoubleAnimationUsingKeyFrames>
                                        < /故事板>
                                    < / BeginStoryboard>
                                < /EventTrigger.Actions>
                            < / EventTrigger中>
                        < /Button.Triggers>
                    < /按钮>
 

解决方案

给你的阴影效果部分名称

 < D​​ropShadowEffect颜色=红色X:名称=阴影效果ShadowDepth =0BlurRadius =21/>
 

和动画透明度中的的TargetName

 < D​​oubleAnimationUsingKeyFrames
    Storyboard.TargetName =阴影效果
    Storyboard.TargetProperty =透明度
    ... />
 

I created a button with Drop Shadow effect. Now i want to add an animation for this effect by changing opacity property during runtime. But this code doesn't work:

<Button x:Name="btnRun" Content="Run" Click="btn_RunEventHandler" BorderThickness="1"  >
                        <Button.Effect>
                            <DropShadowEffect Color="Red"  ShadowDepth="0" BlurRadius="21"  />
                        </Button.Effect>
                        <Button.Triggers>
                            <EventTrigger RoutedEvent="Button.MouseEnter">
                                <EventTrigger.Actions>
                                    <BeginStoryboard>
                                        <Storyboard>
                                            <DoubleAnimationUsingKeyFrames
                                                Storyboard.TargetProperty="(DropShadowEffect.Opacity)"
                                                Duration="0:0:1.6"
                                                RepeatBehavior="Forever">
                                                <LinearDoubleKeyFrame KeyTime="0:0:0" Value="1"/>                                                    
                                                <LinearDoubleKeyFrame KeyTime="0:0:0.5" Value="1"/>
                                                <LinearDoubleKeyFrame KeyTime="0:0:0.55" Value="0"/>
                                                <LinearDoubleKeyFrame KeyTime="0:0:0.6" Value="1"/>
                                                <LinearDoubleKeyFrame KeyTime="0:0:0.7" Value="1"/>
                                                <LinearDoubleKeyFrame KeyTime="0:0:0.8" Value="0.6"/>
                                                <LinearDoubleKeyFrame KeyTime="0:0:1" Value="1"/>
                                                <LinearDoubleKeyFrame KeyTime="0:0:1.6" Value="1"/>
                                            </DoubleAnimationUsingKeyFrames>                                                
                                        </Storyboard>
                                    </BeginStoryboard>
                                </EventTrigger.Actions>
                            </EventTrigger>
                        </Button.Triggers>
                    </Button>

解决方案

Give your DropShadow some name

<DropShadowEffect Color="Red" x:Name="dropShadow" ShadowDepth="0" BlurRadius="21"  />

and animate Opacity of that TargetName

<DoubleAnimationUsingKeyFrames
    Storyboard.TargetName="dropShadow"
    Storyboard.TargetProperty="Opacity"
    .../>

这篇关于改变使用动画不透明度WPF按钮属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆