如何检查窗口是否打开。可能吗?
例如:

if (window.IsOpen)
{
    // window is open
}
else
{
    // window is not open
}

最佳答案

要检查当前应用程序中是否显示窗口:

if(System.Windows.Application.Current.Windows.Contains(yourWindow)) {
    // the window has been shown
} else {
    yourWindow.Show();
}


要检查窗口是否未最小化:

if(yourWindow.WindowState != WindowState.Minimized) {
    // the window is currently not minimized
} else {
    yourWindow.WindowState = WindowState.Normal;
    // or WindowState.Maximized
}

09-27 19:40