/// <summary> /// Returns existing window or null. /// </summary> /// <param name="category"></param> /// <returns></returns> public static Window?TryActivateExistingWindow(string category) { List <WindowSlot>?windowSlots; if (!WindowSlotsDictionary.TryGetValue(category, out windowSlots)) { return(null); } WindowSlot?occupiedWindowSlot = windowSlots.FirstOrDefault(slot => slot.Window is not null); if (occupiedWindowSlot is null) { return(null); } occupiedWindowSlot.Window?.Activate(); return(occupiedWindowSlot.Window); }
public static void InitializeWindow(Window window, string category, bool rememberSize, double initialWidth = Double.NaN, double initialHeight = Double.NaN) { List <WindowSlot>?windowSlots; if (!WindowSlotsDictionary.TryGetValue(category, out windowSlots)) { windowSlots = new List <WindowSlot>(); WindowSlotsDictionary[category] = windowSlots; } WindowSlot?freeWindowSlot = windowSlots.FirstOrDefault(slot => slot.Window is null); if (freeWindowSlot is null) { var rect = new Rect(Double.NaN, Double.NaN, Double.NaN, Double.NaN); if (category != "") { RegistryKey?registryKey = GetOrCreateSszRegistryKey(); if (registryKey is not null) { string?rectString = registryKey.GetValue(category) as string; if (rectString is not null) { var registryRect = (RegistryRect)NameValueCollectionValueSerializer <RegistryRect> .Instance.ConvertFromString(rectString); rect = new Rect(registryRect.X, registryRect.Y, registryRect.Width, registryRect.Height); } } } freeWindowSlot = new WindowSlot { Num = windowSlots.Count, Location = rect }; windowSlots.Add(freeWindowSlot); } freeWindowSlot.Window = window; var windowInfo = new WindowInfo(category, freeWindowSlot.Num); WindowInfosDictionary[window] = windowInfo; Rect slotLocation = freeWindowSlot.Location; if (Double.IsNaN(slotLocation.Width) && !Double.IsNaN(initialWidth)) { slotLocation.Width = initialWidth; } if (Double.IsNaN(slotLocation.Height) && !Double.IsNaN(initialHeight)) { slotLocation.Height = initialHeight; } if (Double.IsNaN(window.Left) && !Double.IsNaN(slotLocation.X)) { window.WindowStartupLocation = WindowStartupLocation.Manual; window.Left = slotLocation.X; } if (Double.IsNaN(window.Top) && !Double.IsNaN(slotLocation.Y)) { window.WindowStartupLocation = WindowStartupLocation.Manual; window.Top = slotLocation.Y; } if (rememberSize) { if (Double.IsNaN(window.Width) && !Double.IsNaN(slotLocation.Width)) { window.WindowStartupLocation = WindowStartupLocation.Manual; window.Width = slotLocation.Width; } if (Double.IsNaN(window.Height) && !Double.IsNaN(slotLocation.Height)) { window.WindowStartupLocation = WindowStartupLocation.Manual; window.Height = slotLocation.Height; } } window.Loaded += (sender, args) => WindowOnLoaded(window); window.Closed += (sender, args) => WindowOnClosed(window); }