c# - 如何在 WPF 中从一个窗口移动到另一个窗口?
问题描述
我正在开发 WPF UI,现在我有一个登录窗口和一个 MainWindow,在 MainWindow 中有多个 userControls,现在当应用程序启动时它会打开登录窗口,我如何移动到 MainWindow 并关闭登录窗口我点击登录按钮??
解决方案
只需关闭登录窗口并打开主窗口。
例如。在按钮单击上
private void LoginButton_Click(object sender, EventArgs args)
{
this.Close();
(new MainWindow()).Open();
}
唯一要记住的是指定ShutdownMode
的默认值是OnLastWindowClose
如果您想坚持使用默认值ShutdownMode
,您可以执行以下操作
private void LoginButton_Click(object sender, EventArgs args)
{
this.Hide(); //first hide the LoginWindow
(new MainWindow()).Open();
this.Close(); //now close the LoginWindow, and the "MainWindow" will be the LastWindow
}
推荐阅读
- android - WorkManager 在应用关闭后停止调度周期性 Worker
- typescript - 无法使用示例“with-firebase-hosting-and-typescript”在 next.js 中呈现图像
- javascript - 从 Django 模板向 JavaScript 函数传递参数时出现语法错误
- python - 无法创建线程,因为只有当我给它一个长于 1 的字符串时,“需要 1 个位置参数但给定 4 个”
- python - 通过在数据框 python pandas 的转置上从另一列切片字符串的新列
- algorithm - 使用 CP 优化器进行电池调度
- java - 如何将文件从特定行读取到另一特定行?
- django - 如何在 Django 中自动创建或更新超级用户?
- ios - iOS模拟器的PJSIP库编译错误
- python - Qt QScrollBar 改变背景颜色