using System.Windows; using System.Windows.Interop; namespace ShrlAlgo.Toolkit.Core.Heplers; public static class SingletonChildWindowManager { private static readonly Dictionary Windows = []; public static void ShowOrActivate(params object[] viewModelParams) where TWindow : Window, new() where TViewModel : class { var windowType = typeof(TWindow); if (Windows.TryGetValue(windowType, out var window) && window != null) { window.Activate(); } else { //CloseAllWindowsExcept(windowType); Windows[windowType] = new TWindow(); Windows[windowType].Closed += (_, _) => Windows[windowType] = null; if (Windows[windowType].DataContext == null || Windows[windowType].DataContext is not TViewModel) { Windows[windowType].DataContext = viewModelParams.Length == 0 ? Activator.CreateInstance() : Activator.CreateInstance(typeof(TViewModel), viewModelParams); } _ = new WindowInteropHelper(Windows[windowType]) { Owner = System.Diagnostics.Process.GetCurrentProcess().MainWindowHandle }; Windows[windowType].Show(); } } }