static private void WindowActionFunc(object sender, ExecutedRoutedEventArgs e, WindowCommandType commandType) { Action <Window>?action = commandType switch { WindowCommandType.CloseWindow => new Action <Window>(SystemCommands.CloseWindow), WindowCommandType.MaximizeWindow => new Action <Window>(SystemCommands.MaximizeWindow), WindowCommandType.MinimizeWindow => new Action <Window>(SystemCommands.MinimizeWindow), WindowCommandType.RestoreWindow => new Action <Window>(SystemCommands.RestoreWindow), _ => null }; if (action == null) { return; } var turget = sender; while (turget is FrameworkElement element) { if (element is Window) { break; } turget = element.Parent; } if (turget is Window window) { action(window); } } }
public WindowCommand(WindowCommandType commandType) { _commandType = commandType; }
static ExecutedRoutedEventHandler GetEventHandler(WindowCommandType commandType) { return(new ExecutedRoutedEventHandler((obj, t) => WindowActionFunc(obj, t, commandType))); }