PowerToys/Wox/Helper/SingletonWindowOpener.cs

20 lines
472 B
C#
Raw Normal View History

using System;
using System.Linq;
using System.Windows;
namespace Wox.Helper
{
2015-02-21 21:57:00 +08:00
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;
}
}
}