private static void SetStartupLocation(Window window, WindowInfo owner, WindowInitialPosition position) { switch (position) { case WindowInitialPosition.CenterOwner: window.WindowStartupLocation = owner != null ? WindowStartupLocation.CenterOwner : WindowStartupLocation.CenterScreen; break; case WindowInitialPosition.CenterScreen: window.WindowStartupLocation = WindowStartupLocation.CenterScreen; break; case WindowInitialPosition.MouseCursor: window.WindowStartupLocation = WindowStartupLocation.Manual; window.Loaded += PositionWindowToMouseCursor; break; default: throw new ArgumentOutOfRangeException(nameof(position), position, null); } }
public static void ShowNonModal(Window window, WindowOwner windowOwner = WindowOwner.MainWindow, WindowInitialPosition position = WindowInitialPosition.CenterOwner) { if (window == null) throw new ArgumentNullException(nameof(window)); CheckDispatcher(); var owner = FindNextOwner(windowOwner); window.Owner = owner?.Window; SetStartupLocation(window, owner, position); var windowInfo = new WindowInfo(window); AllWindowsList.Add(windowInfo); Logger.Info($"Non-modal window showing. ({window})"); window.Show(); }
public static Task ShowModal(Window window, WindowOwner windowOwner = WindowOwner.LastModal, WindowInitialPosition position = WindowInitialPosition.CenterOwner) { if (window == null) throw new ArgumentNullException(nameof(window)); CheckDispatcher(); var windowInfo = new WindowInfo(window); if (ModalWindowsList.Contains(windowInfo)) throw new InvalidOperationException("This window has already been shown as modal."); var owner = FindNextOwner(windowOwner); window.Owner = owner?.Window; SetStartupLocation(window, owner, position); // Set the owner now so the window can be recognized as modal when shown if (owner != null) { owner.IsDisabled = true; } AllWindowsList.Add(windowInfo); switch (windowOwner) { case WindowOwner.LastModal: ModalWindowsList.Add(windowInfo); break; case WindowOwner.MainWindow: ModalWindowsList.Insert(0, windowInfo); break; default: throw new ArgumentOutOfRangeException(nameof(windowOwner), windowOwner, null); } // Update the hwnd on load in case the window is closed before being shown // We will receive EVENT_OBJECT_HIDE but not EVENT_OBJECT_SHOW in this case. window.Loaded += (sender, e) => windowInfo.ForceUpdateHwnd(); Logger.Info($"Modal window showing. ({window})"); window.Show(); return windowInfo.WindowClosed.Task; }
public static void ShowNonModal(Window window, WindowOwner windowOwner = WindowOwner.MainWindow, WindowInitialPosition position = WindowInitialPosition.CenterOwner) { if (window == null) { throw new ArgumentNullException(nameof(window)); } CheckDispatcher(); var owner = FindNextOwner(windowOwner); window.Owner = owner?.Window; SetStartupLocation(window, owner, position); var windowInfo = new WindowInfo(window); AllWindowsList.Add(windowInfo); Logger.Info($"Non-modal window showing. ({window})"); window.Show(); }
public static Task ShowModal(Window window, WindowOwner windowOwner = WindowOwner.LastModal, WindowInitialPosition position = WindowInitialPosition.CenterOwner) { if (window == null) { throw new ArgumentNullException(nameof(window)); } CheckDispatcher(); var windowInfo = new WindowInfo(window); if (ModalWindowsList.Contains(windowInfo)) { throw new InvalidOperationException("This window has already been shown as modal."); } var owner = FindNextOwner(windowOwner); window.Owner = owner?.Window; SetStartupLocation(window, owner, position); // Set the owner now so the window can be recognized as modal when shown if (owner != null) { owner.IsDisabled = true; } AllWindowsList.Add(windowInfo); switch (windowOwner) { case WindowOwner.LastModal: ModalWindowsList.Add(windowInfo); break; case WindowOwner.MainWindow: ModalWindowsList.Insert(0, windowInfo); break; default: throw new ArgumentOutOfRangeException(nameof(windowOwner), windowOwner, null); } // Update the hwnd on load in case the window is closed before being shown // We will receive EVENT_OBJECT_HIDE but not EVENT_OBJECT_SHOW in this case. window.Loaded += (sender, e) => windowInfo.ForceUpdateHwnd(); Logger.Info($"Modal window showing. ({window})"); window.Show(); return(windowInfo.WindowClosed.Task); }