Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
在 WPF 项目中,MainWindow 类与 App 类有什么样的关系?我问的原因是因为在基于 MVVM 设计的项目中,我确实看到了一些可以由 MainWindows.xaml.cs 处理的任务,或者它背后的代码是在 App 类中实现的。
谢谢。
MainWindow 通常App通过StartupUriApp.xaml 中的类连接到类。
App
StartupUri
您可以像这样删除 App.xaml 中的并在 App.xaml.csStartupUri中覆盖OnStartup
OnStartup
protected override void OnStartup(StartupEventArgs e) { var mainWindow = new MainWindow(); mainWindow.DataContext = <your datacontext> mainWindow.Show(); }