App.Xaml的视图模型 [英] A View Model for App.Xaml
本文介绍了App.Xaml的视图模型的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我们可以为App.Xaml使用viewModel吗,以便我们可以在启动时进行一些逻辑推断,也可以构成应用程序的起点...
Can we have a viewModel for App.Xaml so that we can do some logical deductions on startUp and also form a starting point of app...
推荐答案
否,App.xaml不是Window类,而是您的Application类.
No, App.xaml is not a Window class, it is your Application class.
您仍然可以覆盖它的OnStartup()
方法来处理您自己的自定义逻辑并启动特定的Views/ViewModels.
You can still overwrite the OnStartup()
method of it to handle your own custom logic and to startup specific Views/ViewModels.
例如
protected override void OnStartup(StartupEventArgs e)
{
base.OnStartup(e);
var login = new LoginDialog();
var loginVm = new LoginViewModel();
login.DataContext = loginVm;
login.ShowDialog();
if (!login.DialogResult.GetValueOrDefault())
{
Environment.Exit(0);
}
// Providing we have a successful login, startup application
var app = new ShellView();
var context = new ShellViewModel(loginVm.CurrentUser);
app.DataContext = context;
app.Show();
}
这篇关于App.Xaml的视图模型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文