【WPF】更改WPF桌面应用程序的 启动窗口(StartupUri或Startup)
作者:互联网
WPF 更改StartupUri方式
StartupUri指定WPF应用程序启动窗口,默认为MainWindow窗口。
修改方式:
(1)直接修改StartupUri属性,例如:
StartupUri="TestWindow.xam“" 在login项目的根目录下
StartupUri="Views/LoginView.xaml" 在子文件夹下
(2)删掉StartupUri属性,添加Startup事件,例如:Startup="Application_Startup",此事件在对应的隐藏文件中处理(App.xaml.cs)
private void Application_Startup(object sender, StartupEventArgs e) { //Application.Current.StartupUri = new Uri("TestWindow.xaml", UriKind.Relative);//和MainWindwo同一目录 Application.Current.StartupUri = new Uri("com/view/TestWindow.xaml",UriKind.Relative);//在com/view目录下 }
(3)MvvM模式中登入成功后关闭登入窗口,删掉StartupUri属性,添加Startup事件,此事件在对应的隐藏文件中处理(App.xaml.cs)
using System; using System.Collections.Generic; using System.Configuration; using System.Data; using System.Linq; using System.Threading.Tasks; using System.Windows; using Login.Views; namespace Login { /// <summary> /// Interaction logic for App.xaml /// </summary> public partial class App : Application { protected void Application_Startup(object sender, StartupEventArgs e) { var _loginview = new LoginView();//LoginView登入窗口 _loginview.Show(); _loginview.IsVisibleChanged += (se, es) =>{ if (_loginview.Visibility == Visibility.Collapsed && _loginview.IsLoaded) { var modeview = new ModeWindowView(); //ModeWindowView主窗口 modeview.Show(); _loginview.Close(); } }; } } }
标签:StartupUri,Startup,System,Application,loginview,using,WPF 来源: https://www.cnblogs.com/cdaniu/p/16663941.html