using System.Linq; using System.Windows; using System.Threading; using System.Reflection; using SHJX.Service.Common.ElementHelper; namespace PrismMetroSample.Shell.Common { public static class ShellSwitcher { public static void Switch() where TClosed : Window where TShow : Window, new() { Show(); Closed(); } public static void Show(T window = null) where T : Window, new() { var shell = Application.Current.MainWindow = window ?? new T(); shell?.Show(); } public static void Closed() where T : Window { var shell = Application.Current.Windows.OfType().FirstOrDefault(window => window is T); shell?.Close(); } } }