WPF單視窗模式 ActInstance()

西晽發表於2018-12-24

第二次開啟程式中的某個視窗,啟用該視窗

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;
		}
	}
}

相關文章