2010-05-28 47 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

相關問題