2010-05-28 45 views
0

我有一个View.xaml与资源 - 部分中的以下设置:MVVM与动画(?我应该使用VisualStateManager)

<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的变化,我想有一个动画,使当前视图淡出,新观点褪......

不知怎的,我觉得这应该通过VisualStateManag可能呃 - 但我不知道如何!

这是一个WPF 4.0项目......

回答

0

您也许能在你这个问题的答案,以帮助您WPF Fade Animation

他们正在进行FadeIn/FadeOut的可见性。这可能是可以改变从触发...

<Trigger Property="Visibility" Value="Visible"> 

到...

<Trigger Property="Content" Value="{x:Null}"> 

所以我的想法是,在的ViewModels之间的转换,你会做这样的事情

public void SwapViewModels() 
{ 
    // SelectedMyViewModel contains a MyFirstViewModel 
    // Setting to null fires the Animation to fadeout 
    SelectedMyViewModel = null; 

    // Setting the Value to anything but null, should fire the fadein animation 
    SelectedMyViewModel = new MySecondViewModel(); 
} 

我没有测试代码,但希望它给你一个出发点。

+0

对不起,您的回答迟到了,但我又走了一条路 - 但我确定您的回答是正确的 - 因此接受! – kennethkryger 2010-07-29 06:56:43

+0

@kennethkryger:小心添加您的路线作为答案? =) – Jens 2011-07-25 09:51:28

相关问题