应用程序启动检查,我应该在 MVVM 模式中的哪里执行它们?
我想在检查本地文件的数据库连接设置后,使用主视图模型的实例启动 C# / WPF / MVVM 应用程序。
一旦我有了连接设置,我会将它们绑定到一个类并将它们包含在我的主视图模型中。
我想我会检查本地文件并在 App.xaml.cs 中创建主视图模型和主窗口的实例
有什么想法吗?有更好的方法吗?
I would like to start up a C# / WPF / MVVM Application with an instance of my Main View Model after checking a local file for database connection settings.
Once I have the connection settings I will bind them to a class and include them in my Main View Model.
I'm thinking that I would check the local file and create the instances of the Main View Model, and Main Window in App.xaml.cs
Any thoughts ? Is there a better way to do this ?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我通常按照你说的做:在 App.xaml.cs 中创建初始 View 和 ViewModel
I usually do just what you said: create the initial View and ViewModel in
App.xaml.cs
您可以在负责导航(加载(ViewModel 和)View 并侦听导航消息)的单独类中实现此职责。
在 App 类中,您只需实例化并初始化此类。
You could implement this responsibility in a separate class that is responsible for navigation (loading (a ViewModel and) a View and listening for navigation messages).
In the App class you would only have to instantiate and initialize this class.