ColorAnimation颜色错误
wpf吧
全部回复
仅看楼主
level 1
YinYao_隐耀 楼主
WPF新手,问问各位大佬:
我的代码是这样的
<Style x:Key="styleButtonClose" TargetType="Button">
<Setter Property="Width" Value="39"/>
<Setter Property="Height" Value="39"/>
<Setter Property="Background" Value="Transparent"/>
<Setter Property="BorderThickness" Value="0"/>
<Setter Property="Focusable" Value="False"/>
<Style.Triggers>
<EventTrigger RoutedEvent="MouseEnter">
<BeginStoryboard>
<Storyboard>
<ColorAnimation Storyboard.TargetProperty="Background.Color" From="Transparent" To="#EA3447" Duration="0:0:1"/>
</Storyboard>
</BeginStoryboard>
</EventTrigger>
<EventTrigger RoutedEvent="MouseLeave">
<BeginStoryboard>
<Storyboard>
<ColorAnimation Storyboard.TargetProperty="Background.Color" From="#EA3447" To="Transparent" Duration="0:0:1"/>
</Storyboard>
</BeginStoryboard>
</EventTrigger>
</Style.Triggers>
</Style>
理论上来说,MouseEnter时这个按钮的颜色应该是红色(#EA3447),结果却是这样:
但是在MouseLeave时就突然变红,然后动画正常进行
求求了大佬们
2025年04月25日 13点04分 1
level 4
别用eventtrigger去处理button的动画,这会很麻烦。
处理这种复杂状态最好是用VisualState 。
bing搜索【button样式与模板】,看官方文档,了解怎么使用。
简单说就是wpf的控件,默认包含了好几组不同的状态,就是用于切换进入各自状态的动画的。
2025年05月02日 01点05分 2
1