Example #1
0
        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);
            }
        }
    }
Example #2
0
 public WindowCommand(WindowCommandType commandType)
 {
     _commandType = commandType;
 }
Example #3
0
 public WindowCommand(WindowCommandType commandType)
 {
     _commandType = commandType;
 }
Example #4
0
 static ExecutedRoutedEventHandler GetEventHandler(WindowCommandType commandType)
 {
     return(new ExecutedRoutedEventHandler((obj, t) => WindowActionFunc(obj, t, commandType)));
 }