2010-05-28 3 views
0

내가이 자료 섹션에서 설정 다음으로 View.xaml있어 다음 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> 

내가 가진 :

<!-- 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}"> 

그래서 내 생각은 당신이

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(); 
} 
같은 것을 할 것입니다 ViewModels 사이의 전환에 그 것을에서 트리거를 변경 할 수 있습니다

코드를 테스트하지는 않았지만 시작 지점을 제공하기를 바랍니다.

+0

답장을 늦게내어 드려 죄송합니다.하지만 다른 경로로갔습니다. 그러나 귀하의 대답은 정확합니다. 따라서 수용합니다! – kennethkryger

+0

@kennethkryger : 경로를 답으로 추가 할 때주의하십시오. =) – Jens