在VS2012中创建一个新的WPF项目,并添加一个包含以下内容的类:
[System.STAThreadAttribute()]
static void Main(string[] args) {
App app = new App();
MainWindow window = new MainWindow();
window.ShowDialog();
}
将App.xaml的构建操作从ApplicationDefinition更改为Page。将以下代码放在og App.xaml:
后面的代码中protected override void OnStartup(StartupEventArgs e) {
MessageBox.Show("Run() has been called.");
}
有人可以解释为什么在这里调用App.Run()?我使用我的App对象只管理资源,因为我的WPF控件是托管的(article)。
编辑:我认为这里的答案是OnStartup
在没有调用Run()
的情况下被调用。