PowerToys/Wox/Helper/SingletonWindowOpener.cs
2015-10-30 23:23:01 +00:00

20 lines
472 B
C#

using System;
using System.Linq;
using System.Windows;
namespace Wox.Helper
{
public static class SingletonWindowOpener
{
public static T Open<T>(params object[] args) where T : Window
{
var window = Application.Current.Windows.OfType<Window>().FirstOrDefault(x => x.GetType() == typeof(T))
?? (T)Activator.CreateInstance(typeof(T), args);
Application.Current.MainWindow.Hide();
window.Show();
window.Focus();
return (T)window;
}
}
}