WPF单窗口模式 ActInstance()
程序员文章站
2022-03-01 13:04:29
...
第二次打开程序中的某个窗口,**该窗口
namespace Endeavour
{
public partial class Window2 : Window
{
public static Window2 Instance { get; private set; }
public static void ActInstance()
{
if (Instance == null)
{
Instance = new Window2();
Instance.Show();
}
else {
Instance.Activate();
}
}
private Window2()
{
InitializeComponent();
this.Closed += WindowOnClosed;
}
private void WindowOnClosed(object sender, System.EventArgs e)
{
Instance = null;
}
}
}