現在持っているソースコードを投稿し、その後問題を説明します。
これは、移行を実行したいウィンドウです。
<Window x:Class="MyApp.MainView"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="MyApp" Height="600" Width="800">
<StackPanel>
<Button Content="View1" Command="{Binding View1Command}"/>
<Button COntent="View2" Command="{Binding View2Command}"/>
<ContentControl Content="{Binding MyContent}"/>
</StackPanel>
これは関連するビューモデルです
public class MainViewModel
{
public RelayCommand View1Command{ get; private set;}
public RelayCommand View2Command{ get; private set;}
//INotifyPropertyChanged is implemented of course
public ViewModelBase MyContent { get; set;}
public MainViewModel()
{
View1Command = new RelayCommand(() => { MyContent = new ViewModel1();});
View2Command = new RelayCommand(() => { MyContent = new ViewModel2();});
}
}
app.xamlで、データテンプレートを使用して、ViewModel1をView1に関連付け、ViewModel2をView2に関連付けました。それはすべて期待どおりに機能します。ボタンをクリックすると、ビューが変更され、データバインディングが機能し、すべて問題ありません。
私が今やりたいのは、ビューが変わったときにアニメーションを使用することです。
新しいビューのフェードインアニメーションを使用して、2つのビュー間の遷移をアニメーション化するにはどうすればよいですか。古いビューが消え、新しいビューが1秒以内にフェードインします。
あなたが私を助けてくれることを願っています。
よろしくお願いします
パスカル
psデータテンプレートを使用したアプローチが意味をなさず、そのアプローチでアニメーションが不可能な場合は、他のベストプラクティスをオンビューから別のビューに変更できます。私が使用するソリューションは、karl shiffletによるwpfデモアプリから取得されますが、それが私がやろうとしていることに対して正しいソリューションであるかどうかはわかりません。