使用动画更改不透明度 WPF 按钮 属性
Changing opacity WPF Button property using Animation
我创建了一个带有投影效果的按钮。现在我想通过在运行时更改不透明度 属性 来为此效果添加动画。但是这段代码不起作用:
<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>
给你的 DropShadow
取个名字
<DropShadowEffect Color="Red" x:Name="dropShadow" ShadowDepth="0" BlurRadius="21" />
并为 TargetName
的 Opacity
制作动画
<DoubleAnimationUsingKeyFrames
Storyboard.TargetName="dropShadow"
Storyboard.TargetProperty="Opacity"
.../>
我创建了一个带有投影效果的按钮。现在我想通过在运行时更改不透明度 属性 来为此效果添加动画。但是这段代码不起作用:
<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>
给你的 DropShadow
取个名字
<DropShadowEffect Color="Red" x:Name="dropShadow" ShadowDepth="0" BlurRadius="21" />
并为 TargetName
Opacity
制作动画
<DoubleAnimationUsingKeyFrames
Storyboard.TargetName="dropShadow"
Storyboard.TargetProperty="Opacity"
.../>