App.xaml.cs で OnStartup() メソッドをオーバーライドする
(2017/03/07 15:26:51 created.)
(2017/03/07 15:29:35 modified.)
App クラスの OnStartup() メソッドは、アプリケーション起動時に呼ばれるメソッドです。ここで View に対する DataContext プロパティの設定と、Show() メソッド呼び出しによるウィンドウの表示をおこないます。実際のコードは次のようになります。
title
namespace Tips_Sample
{
using System.Windows;
using Tips_Sample.ViewModels;
using Tips_Sample.Views;
/// <summary>
/// App.xaml の相互作用ロジック
/// </summary>
public partial class App : Application
{
protected override void OnStartup(StartupEventArgs e)
{
base.OnStartup(e);
var w = new MainView();
var vm = new MainViewModel();
w.DataContext = vm;
w.Show();
}
}
}
Tweet