带动画的 MVVM(我应该使用 VisualStateManager 吗?)
我在资源部分有一个 View.xaml ,其中包含以下设置:
<DataTemplate DataType="{x:Type ViewModels:MyFirstViewModel}">
<Views:MyFirstView Content="{Binding}" />
</DataTemplate>
<DataTemplate DataType="{x:Type ViewModels:MySecondViewModel}">
<Views:MySecondView Content="{Binding}"/>
</DataTemplate>
在 View.xaml 的内容中,我有:
<!-- SelectedMyViewModel is either set to MyFirstViewModel or MySecondViewModel -->
<ContentControl Content="{Binding SelectedMyViewModel}" />
当 SelectedMyViewModel 更改时,我想要一个动画,以便当前视图淡出并新视图淡入...
不知何故,我觉得这应该可以通过 VisualStateManager 实现 - 但我不知道如何实现!
这是一个 WPF 4.0 项目...
I've got a View.xaml with the following set in Resources-section:
<DataTemplate DataType="{x:Type ViewModels:MyFirstViewModel}">
<Views:MyFirstView Content="{Binding}" />
</DataTemplate>
<DataTemplate DataType="{x:Type ViewModels:MySecondViewModel}">
<Views:MySecondView Content="{Binding}"/>
</DataTemplate>
In the content of the View.xaml I have:
<!-- SelectedMyViewModel is either set to MyFirstViewModel or MySecondViewModel -->
<ContentControl Content="{Binding SelectedMyViewModel}" />
When the SelectedMyViewModel changes I'd like to have a animation, so that the current view is faded out and the new view is faded in...
Somehow I feel this should be possible via the VisualStateManager - but I can't figure out how!
This is a WPF 4.0 project...
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您也许可以找到此问题的答案来帮助您WPF 淡入淡出动画。
他们正在对可见性进行淡入/淡出。可能可以将触发器从...更改
为...
所以我的想法是,在 ViewModel 之间转换时,您会做一些类似
我没有测试代码的事情,但希望它能为您提供一个起点。
You maybe able to you the answer in this question to assist you WPF Fade Animation.
They are doing a FadeIn/FadeOut on visibility. It might be possible to change the Trigger from...
to...
So my idea would be that in transitioning between ViewModels you would do something like
I haven't tested the code but hopefully it gives you a starting point.