PowerToys/Wox/Helper/SingletonWindowOpener.cs
bao-qian b22a4501cc Use variable instead of global static method
1. introduce variable
2. part of #389
3. refactoring program suffix in program plugin
4. 全局变量一时爽,代码重构火葬场
2016-03-28 03:09:57 +01:00

20 lines
539 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);
App.API.HideApp();
window.Show();
window.Focus();
return (T)window;
}
}
}