gpt4 book ai didi

c# - 仅在鼠标离开时自动反转为原始颜色

转载 作者:太空宇宙 更新时间:2023-11-03 20:15:08 24 4
gpt4 key购买 nike

我在 .Net Framework 4 中使用 WPF。
我创建了一个背景色为 X 的按钮。
我为按钮创建了一个样式,在 IsMouseOver 上启动 ColorAnimation,将背景颜色更改为蓝色。

如果 IsMouseOver 为 false(鼠标没有记录在按钮上),我想将按钮背景恢复为颜色 X。

示例代码:

<Trigger Property="IsMouseOver" Value="True">
<Trigger.EnterActions>
<BeginStoryboard>
<Storyboard>
<ColorAnimation Duration="0:0:0.5" Storyboard.TargetName="MyButton" Storyboard.TargetProperty="Fill.Color" To="Blue"/>
</Storyboard>
</BeginStoryboard>
</Trigger.EnterActions>
</Trigger>

我该怎么做?

最佳答案

您可以指定 ExitActionsEnterActions 并且不要设置 To 属性,以便它回退到原始值 -

<Trigger.ExitActions>
<BeginStoryboard>
<Storyboard>
<ColorAnimation Duration="0:0:0.5"
Storyboard.TargetName="MyButton"
Storyboard.TargetProperty="Background.Color"/>
</Storyboard>
</BeginStoryboard>
</Trigger.ExitActions>

关于c# - 仅在鼠标离开时自动反转为原始颜色,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17388211/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com