mirror of
https://github.com/microsoft/PowerToys.git
synced 2026-04-06 03:07:04 +02:00
Feature: Added WindowOpener class, which prevents having duplicate windows of the same type opened at the same time
This commit is contained in:
22
Wox/Helper/WindowOpener.cs
Normal file
22
Wox/Helper/WindowOpener.cs
Normal file
@@ -0,0 +1,22 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Windows;
|
||||
|
||||
namespace Wox.Helper
|
||||
{
|
||||
public static class WindowOpener
|
||||
{
|
||||
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);
|
||||
window.Show();
|
||||
window.Focus();
|
||||
Application.Current.MainWindow.Hide();
|
||||
|
||||
return (T)window;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user