[英]Smooth ExitAction in WPF Trigger using Storyboard
I have a WPF aplication and here I want to override the ugly default WPF styles. 我有一个WPF应用程序,在这里我想覆盖难看的默认WPF样式。 I have created the Styles.xaml dictionary and here I have almost finished with styles, but there are some problems with animation and smooth transition between different visual states (triggers).
我创建了Styles.xaml词典,在这里我几乎完成了样式,但是在动画和不同视觉状态(触发)之间的平滑过渡方面存在一些问题。
One of my challenges was that I don't want to have any C# event handlers or other C# code bound to styles. 我的挑战之一是我不想将任何C#事件处理程序或其他C#代码绑定到样式。
Here I provide some code on my trigger: 在这里,我在触发器上提供了一些代码:
<MultiTrigger>
<MultiTrigger.Conditions>
<Condition Property="IsEnabled" Value="True" />
<Condition Property="IsMouseOver" Value="True" />
<Condition Property="IsPressed" Value="False" />
</MultiTrigger.Conditions>
<MultiTrigger.EnterActions>
<BeginStoryboard Name="MouseOverStoryboard">
<Storyboard Duration="0:0:0.25" SlipBehavior="Grow">
<ColorAnimation Storyboard.TargetName="InnerBorder"
Storyboard.TargetProperty="Background.(SolidColorBrush.Color)"
To="{StaticResource White}"
BeginTime="0:0:0" Duration="0:0:0.25" />
<DoubleAnimation Storyboard.TargetName="InnerBorder"
Storyboard.TargetProperty="Opacity"
To="0.3"
BeginTime="0:0:0" Duration="0:0:0.25" />
</Storyboard>
</BeginStoryboard>
</MultiTrigger.EnterActions>
<MultiTrigger.ExitActions>
<RemoveStoryboard BeginStoryboardName="MouseOverStoryboard" />
</MultiTrigger.ExitActions>
</MultiTrigger>
To make animation smooth I added EnterAction and put Storyboard here with timings, so entering animation is smooth and looking well. 为了使动画更流畅,我添加了EnterAction并将Storyboard与时序一起放置在此处,因此输入动画很流畅且看起来不错。
My first question was about how to get back to default color when my BeginStoryboard was executed, but then I realised I can use RemoveStoryboard. 我的第一个问题是关于执行BeginStoryboard时如何恢复默认颜色,但后来我意识到可以使用RemoveStoryboard。
Now I really don't know I my ideas are out - how to make smooth exit animation? 现在我真的不知道我的想法出了点-如何制作流畅的退出动画? Shouldn't I use RemoveStoryboard?
我不应该使用RemoveStoryboard吗?
Please provide suggestions. 请提供建议。 Thanks.
谢谢。
PS I'm not using VisualStateManager, because of lack of states and I don't want to implement my own controls for that. PS我不使用VisualStateManager,因为缺乏状态,我不想为此实现自己的控件。
How about adding a new animation object that starts when the enter action animation duration elapsed. 如何添加一个新的动画对象,该对象在输入动作动画持续时间过去后开始。 Or how about using the
ExitAction
property of your Trigger by adding a Storyboard
that reverts your EnterAction
. 或通过添加一个
Storyboard
来还原您的EnterAction
来使用触发器的ExitAction
属性。 Or you could try to set the Fillbehavior
property to 'Stop... 或者您可以尝试将
Fillbehavior
属性设置为“停止...”。
Another option is to use an EventSetter
to catch RoutedEvents
like MouseEnter
and MouseLeave
. 另一个选择是使用
EventSetter
来捕获RoutedEvents
例如MouseEnter
和MouseLeave
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.