4 using System.Windows.Controls;
5 using System.Windows.Input;
6 using System.Windows.Interop;
8 using SiliconStudio.Presentation.Extensions;
10 namespace SiliconStudio.Presentation.
Commands
19 MinimizeWindowCommand =
new SystemCommand(CanMinimize, Minimize);
20 MaximizeWindowCommand =
new SystemCommand(CanMaximize, Maximize);
21 RestoreWindowCommand =
new SystemCommand(CanRestore, Restore);
22 CloseWindowCommand =
new SystemCommand(CanClose, Close);
23 ShowSystemMenuCommand =
new SystemCommand(CanShowSystemMenu, ShowSystemMenu);
29 public static ICommand MinimizeWindowCommand {
get;
private set; }
34 public static ICommand MaximizeWindowCommand {
get;
private set; }
39 public static ICommand RestoreWindowCommand {
get;
private set; }
44 public static ICommand CloseWindowCommand {
get;
private set; }
49 public static ICommand ShowSystemMenuCommand {
get;
private set; }
51 private static bool CanMinimize(
Window window)
53 return HasFlag(window, NativeHelper.WS_MINIMIZEBOX);
56 private static void Minimize(
Window window)
58 System.Windows.SystemCommands.MinimizeWindow(window);
61 private static bool CanMaximize(
Window window)
63 return HasFlag(window, NativeHelper.WS_MAXIMIZEBOX);
66 private static void Maximize(
Window window)
68 System.Windows.SystemCommands.MaximizeWindow(window);
71 private static bool CanRestore(
Window window)
73 return HasFlag(window, NativeHelper.WS_MAXIMIZEBOX);
76 private static void Restore(
Window window)
78 System.Windows.SystemCommands.RestoreWindow(window);
81 private static bool CanClose(
Window window)
86 private static void Close(
Window window)
88 System.Windows.SystemCommands.CloseWindow(window);
91 private static bool CanShowSystemMenu(
Window window)
93 return window != null && HasFlag(window, NativeHelper.WS_SYSMENU);
96 private static void ShowSystemMenu(
Window window)
100 var presenter = window.FindVisualChildrenOfType<ContentPresenter>().FirstOrDefault(x => Equals(x.FindVisualParentOfType<
Control>(), window));
101 if (presenter == null)
102 throw new InvalidOperationException(
"The given window does not contain a ContentPresenter.");
104 System.Windows.SystemCommands.ShowSystemMenu(window, presenter.PointToScreen(
new Point(0, 0)));
107 private static bool HasFlag(
Window window,
int flag)
109 var hwnd =
new WindowInteropHelper(window).Handle;
110 bool hasFlag = (NativeHelper.GetWindowLong(hwnd, NativeHelper.GWL_STYLE) & flag) != 0;
A static class containing system commands to control a window.
System.Windows.Point Point