【WPF】关闭非装窗体以外所有窗体

来源:互联网 发布:网络基础知识说课ppt 编辑:程序博客网 时间:2024/05/17 22:13


XX.MainWindow=>是想要保留窗体的命名

 

///<summary>

/// 关闭非装窗体以外所有窗体

///</summary>

privatevoid CloseForm()

{

int n = Application.Current.Windows.Count;

for (int a = 0; a < n; a++)

{

for (int i = 0; i < Application.Current.Windows.Count; i++)

{

string x = Application.Current.Windows[i].ToString();

if (x != "XX.MainWindow")Application.Current.Windows[i].Close();

}

}

}

原创粉丝点击