@@ -19,6 +19,11 @@ public MainWindow()
1919 InitializeComponent ( ) ;
2020 DataContext = _viewModel ;
2121
22+ CommandBindings . Add ( new CommandBinding ( SystemCommands . CloseWindowCommand , OnCloseWindow ) ) ;
23+ CommandBindings . Add ( new CommandBinding ( SystemCommands . MaximizeWindowCommand , OnMaximizeWindow , OnCanResizeWindow ) ) ;
24+ CommandBindings . Add ( new CommandBinding ( SystemCommands . MinimizeWindowCommand , OnMinimizeWindow , OnCanMinimizeWindow ) ) ;
25+ CommandBindings . Add ( new CommandBinding ( SystemCommands . RestoreWindowCommand , OnRestoreWindow , OnCanResizeWindow ) ) ;
26+
2227 if ( Environment . GetCommandLineArgs ( ) . Length > 0 )
2328 {
2429 foreach ( string arg in Environment . GetCommandLineArgs ( ) )
@@ -54,4 +59,34 @@ private void ValidateFloatTextBox(object sender, TextCompositionEventArgs e)
5459 e . Handled = ! float . TryParse ( text , out _ ) || text . Contains ( "," ) ;
5560 }
5661 }
62+
63+ private void OnCanResizeWindow ( object sender , CanExecuteRoutedEventArgs e )
64+ {
65+ e . CanExecute = ResizeMode == ResizeMode . CanResize || ResizeMode == ResizeMode . CanResizeWithGrip ;
66+ }
67+
68+ private void OnCanMinimizeWindow ( object sender , CanExecuteRoutedEventArgs e )
69+ {
70+ e . CanExecute = ResizeMode != ResizeMode . NoResize ;
71+ }
72+
73+ private void OnCloseWindow ( object target , ExecutedRoutedEventArgs e )
74+ {
75+ SystemCommands . CloseWindow ( this ) ;
76+ }
77+
78+ private void OnMaximizeWindow ( object target , ExecutedRoutedEventArgs e )
79+ {
80+ SystemCommands . MaximizeWindow ( this ) ;
81+ }
82+
83+ private void OnMinimizeWindow ( object target , ExecutedRoutedEventArgs e )
84+ {
85+ SystemCommands . MinimizeWindow ( this ) ;
86+ }
87+
88+ private void OnRestoreWindow ( object target , ExecutedRoutedEventArgs e )
89+ {
90+ SystemCommands . RestoreWindow ( this ) ;
91+ }
5792}
0 commit comments