wpf - 如何使用MVVM启动动画?

标签 wpf mvvm

我正在使用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/

相关文章:

c# - 不能在 'Binding' 类型的 'Source' 属性上设置 'Binding'

c# - 如何从 C# 代码中调用 Command 而不是通过将 UI 控件绑定(bind)到它?

c# - 仅更改选定行的 Horizo​​ntalGridLinesBrush

wpf - WPF设计时间数据困惑

silverlight - Prism MVVM - 如何将 IEventAggregator 传递给我的 ViewModel

silverlight - Silverlight和M-V-VM-计时器应该放在哪里?

c# - Canvas 覆盖了里面 TextBlock 的 TextAlignment 值

c# - 检查kinect是否连接

c# - 为什么 RelayCommand<T>.Execute 采用对象而不是 T?

c# - WPF套接字客户端结构