关于登陆窗口无法跳转到主窗口的问题
private void Application_Startup(object sender, StartupEventArgs e){this.RootVisual = new MyLogin();//我用这种方式先打开登陆界面}
private void OKButton_Click(object sender, RoutedEventArgs e){ this.DialogResult = true; string loginUserName = txtUseName.Text.Trim(); string passWord = txtPassword.Text.Trim(); if (loginUserName == "441350" && passWord == "123456") { this.Close(); MainPage mainpage = new MainPage(); App.Current.RootVisual = mainpage;//但是主窗口无法出来。。。 } else { MessageBox.Show("用户名或密码错误"); return; }}
private void Application_Startup(object sender, StartupEventArgs e) { ChildWindow login = new LoginWindow(); Grid rootPanel = new Grid(); this.RootVisual = rootPanel; login.Closed += (s, arg) => { // 只有登录成功DialogResult才为True,其他情况将DialogResult设置为false即可 if (login.DialogResult == true) { rootPanel.Children.Add(new MainPage()); } else { System.Windows.Browser.HtmlPage.Window.Invoke("close"); } }; // 显示登录 login.Show(); }