WPF。如何从另一个窗口隐藏/显示主窗口
我有两个窗口 MainWindow 和 Login。 位于登录窗口主窗口上的显示登录的按钮
this.Hide();
Login li = new Login();
li.Show();
是检查密码的按钮,如果密码正确,我如何显示主窗口?
I have Two windows MainWindow and Login.
The button which shows login located on mainWindow
this.Hide();
Login li = new Login();
li.Show();
on Login Window is button which checks password how i can show MainWindow if password is correct?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
将参数传递给 MainWindow 类型的登录窗口。这允许登录窗口引用主窗口:
登录窗口:
pass a parameter to the loginwindow of type MainWindow. That allows the Login window to have a reference to the MainWindow:
And the login window:
第一个答案很好,但它会创建一个新的空窗口
为了避免这个问题(重定向到以前创建的窗口)只需修改构造函数,如下所示
first answer is good but it'll create a new empty window
to avoid this problem ( redirect to a previously created window) just modify constructor like this
怎么样...
确保您的登录名中有类似...
What about....
Make sure in your Login you have something like...
您的用户界面使用什么类型的布局等?如果您将登录窗口设置为模式对话框,那么您是否需要隐藏主窗口?
或者,您可以拥有某种“成功登录”标志,并将每个窗口的可见性绑定到该值 - 使用转换器来获得所需的结果?大致意思是:
这有意义吗?
编辑:显然网格中的元素实际上不能是Windows - 因此我最初的问题是关于您正在使用的布局!
What sort of layout, etc are you using for your UI? If you make the log in window a modal dialog then do you need to hide the main window?
Alternatively, you could have some sort of 'successfully logged in' flag and bind the visibility of each window to this value - using converters to get the desired result? Something along the lines of:
Does that make sense?
EDIT: Obviously the elements within the Grid can't actually be Windows - hence my initial question about the layout you are using!