如何在不打开WPF多个窗口 [英] How to not open multiple windows in WPF

查看:504
本文介绍了如何在不打开WPF多个窗口的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的WPF应用程序,我用这个code从一个按钮打开一个新的窗口:

In my WPF application I use this code to open a new windows from a button:

private void LoginBtn_Click(object sender, RoutedEventArgs e)
{
    LoginDialog dialog = new LoginDialog();
    dialog.Show();    
}

但如果已经有一个开放的LoginDialog,我再次点击LoginBtn它打开一个新窗口的LoginDialog。我如何code,以便它覆盖previous一个是开放的,如果有的话。

But when there is already a LoginDialog open and I click the LoginBtn again it open a new LoginDialog windows. How do I code it so it override the previous one that is open, if any.

推荐答案

您可以创建类型登录对话框中的局部变量,并检查其空

You can create a local variable of type Login dialog and check if its null

LoginDialog _dialog;

private void LoginBtn_Click(object sender, RoutedEventArgs e)
{
    if(_dialog == null)
    {
        _dialog = new LoginDialog();
     }
    _dialog.Show();    
}

这篇关于如何在不打开WPF多个窗口的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆