我正在使用WPF和MVVM模式转换现有的应用程序。
我认为我有不同的 Storyboard。
例如。 1.加载应用程序时显示启动画面
2.在单击菜单切换按钮/单选按钮以显示幻灯片和幻灯片动画效果时
3.对于 View 中可用的不同元素,鼠标悬停效果也不同。
我将如何使用MVVM调用 Storyboard ,这是最好的方法?为了显示鼠标悬停效果,我们真的必须使用MVVM或后面的代码吗?
最佳答案
对于问题1,我不确定您的要求或执行此操作的最佳方法,但是一个想法是您可以使用类似于下面的#3的代码,但可以将<EventTrigger RoutedEvent="Mouse.MouseEnter">
替换为<EventTrigger RoutedEvent="Window.Loaded">
要回答问题2,这是当用户更改单选按钮时如何启动 Storyboard 的方法。这就是XAML中的全部内容:
<CheckBox Content="Radio Button Option 1" >
<i:Interaction.Triggers>
<i:EventTrigger EventName="Checked">
<im:ControlStoryboardAction Storyboard="{StaticResource NameOfStoryboardToRunOnCheck}"/>
</i:EventTrigger>
<i:EventTrigger EventName="Unchecked">
<im:ControlStoryboardAction Storyboard="{StaticResource NameOfStoryboardToRunOnUnCheck}"/>
</i:EventTrigger>
</i:Interaction.Triggers>
</CheckBox>
对于问题3,这是OnMouseOver的示例
<UserControl.Triggers>
<EventTrigger RoutedEvent="Mouse.MouseEnter">
<BeginStoryboard Storyboard="{StaticResource MouseOverStoryboard}" />
</EventTrigger>
<EventTrigger RoutedEvent="Mouse.MouseLeave">
<BeginStoryboard Storyboard="{StaticResource MouseLeaveStoryboard}" />
</EventTrigger>
</UserControl.Triggers>
关于wpf - 如何使用MVVM启动动画?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3027485/