我有一个窗口弹出,如果一个已经不存在的主窗口创建:如何引用当前打开的窗口在WPF
if (App.Current.MainWindow != null && App.Current.MainWindow.GetType() == typeof(MainWindow))
{
this.Close();
}
else
{
//main Window hasn't been created yet so create it!
MainWindow main = new MainWindow();
App.Current.MainWindow = main;
this.Close();
main.Show();
wndw = main;
}
如何我指的是主窗口,所以我可以使用它在if语句之外?
我希望能够做main.txbox.Text = ....
等
这是我已经试过:
MainWindow main;
if
{...
}
else
{...
}
main= App.Current.MainWindow;
或MainWindow main = App.Current.MainWindow();
的这两种方法都不似乎工作。我确信这很简单,我只是无法弄清楚语法。帮帮我?
编辑:于this question类似我刚才问的,但不同的,因为在这里我要问有关语法引用当前打开的窗口时。类似的问题是指如何检测打开哪个窗口。他们很相似,但我不想脱离主题。
请继续你你问[这里]的问题(http://stackoverflow.com/questions/31542339/how-do-i-decide-是否对创建-A-新窗口时-I-点击上一个按钮/ 31542565?noredirect = 1#comment51045144_31542565) – Muds
这是非常糟糕的主意,直写,例如文本框另一个窗口控件。最好由绑定的属性来做到这一点。 – Marcin
@Muds发布的新问题新的疑问是完全正常的。帮助保持其他问题不受干扰。 – almulo