@@ -108,50 +108,68 @@ private void AppButton_OnContextMenuOpening(object sender, ContextMenuEventArgs
108108 int ws = Window . WindowStyles ;
109109
110110 // disable window operations depending on current window state. originally tried implementing via bindings but found there is no notification we get regarding maximized state
111- MaximizeMenuItem . IsEnabled = ( wss != NativeMethods . WindowShowStyle . ShowMaximized && ( ws & ( int ) NativeMethods . WindowStyles . WS_MAXIMIZEBOX ) != 0 ) ;
112- MinimizeMenuItem . IsEnabled = ( wss != NativeMethods . WindowShowStyle . ShowMinimized && ( ws & ( int ) NativeMethods . WindowStyles . WS_MINIMIZEBOX ) != 0 ) ;
113- if ( RestoreMenuItem . IsEnabled = ( wss ! = NativeMethods . WindowShowStyle . ShowNormal ) )
111+ MaximizeMenuItem . StaysOpenOnClick = ! ( wss != NativeMethods . WindowShowStyle . ShowMaximized && ( ws & ( int ) NativeMethods . WindowStyles . WS_MAXIMIZEBOX ) != 0 ) ;
112+ MinimizeMenuItem . StaysOpenOnClick = ! ( wss != NativeMethods . WindowShowStyle . ShowMinimized && ( ws & ( int ) NativeMethods . WindowStyles . WS_MINIMIZEBOX ) != 0 ) ;
113+ if ( ! ( RestoreMenuItem . StaysOpenOnClick = wss = = NativeMethods . WindowShowStyle . ShowNormal ) )
114114 {
115115 CloseMenuItem . FontWeight = FontWeights . Normal ;
116116 RestoreMenuItem . FontWeight = FontWeights . Bold ;
117117 }
118- if ( ! RestoreMenuItem . IsEnabled || RestoreMenuItem . IsEnabled && ! MaximizeMenuItem . IsEnabled )
118+ if ( RestoreMenuItem . StaysOpenOnClick || ! RestoreMenuItem . StaysOpenOnClick && MaximizeMenuItem . StaysOpenOnClick )
119119 {
120120 CloseMenuItem . FontWeight = FontWeights . Bold ;
121121 RestoreMenuItem . FontWeight = FontWeights . Normal ;
122122 }
123- MoveMenuItem . IsEnabled = wss = = NativeMethods . WindowShowStyle . ShowNormal ;
124- SizeMenuItem . IsEnabled = ( wss == NativeMethods . WindowShowStyle . ShowNormal && ( ws & ( int ) NativeMethods . WindowStyles . WS_MAXIMIZEBOX ) != 0 ) ;
123+ MoveMenuItem . StaysOpenOnClick = wss ! = NativeMethods . WindowShowStyle . ShowNormal ;
124+ SizeMenuItem . StaysOpenOnClick = ! ( wss == NativeMethods . WindowShowStyle . ShowNormal && ( ws & ( int ) NativeMethods . WindowStyles . WS_MAXIMIZEBOX ) != 0 ) ;
125125 }
126126
127127 private void CloseMenuItem_OnClick ( object sender , RoutedEventArgs e )
128128 {
129- Window ? . Close ( ) ;
129+ if ( ! ( ( MenuItem ) sender ) . StaysOpenOnClick )
130+ {
131+ Window ? . Close ( ) ;
132+ }
130133 }
131134
132135 private void RestoreMenuItem_OnClick ( object sender , RoutedEventArgs e )
133136 {
134- Window ? . Restore ( ) ;
137+ if ( ! ( ( MenuItem ) sender ) . StaysOpenOnClick )
138+ {
139+ Window ? . Restore ( ) ;
140+ }
135141 }
136142
137143 private void MoveMenuItem_OnClick ( object sender , RoutedEventArgs e )
138144 {
139- Window ? . Move ( ) ;
145+ if ( ! ( ( MenuItem ) sender ) . StaysOpenOnClick )
146+ {
147+ Window ? . Move ( ) ;
148+ }
140149 }
141150
142151 private void SizeMenuItem_OnClick ( object sender , RoutedEventArgs e )
143152 {
144- Window ? . Size ( ) ;
153+ if ( ! ( ( MenuItem ) sender ) . StaysOpenOnClick )
154+ {
155+ Window ? . Size ( ) ;
156+ }
145157 }
146158
147159 private void MinimizeMenuItem_OnClick ( object sender , RoutedEventArgs e )
148160 {
149- Window ? . Minimize ( ) ;
161+ if ( ! ( ( MenuItem ) sender ) . StaysOpenOnClick )
162+ {
163+ Window ? . Minimize ( ) ;
164+ }
150165 }
151166
152167 private void MaximizeMenuItem_OnClick ( object sender , RoutedEventArgs e )
153168 {
154- Window ? . Maximize ( ) ;
169+ if ( ! ( ( MenuItem ) sender ) . StaysOpenOnClick )
170+ {
171+ Window ? . Maximize ( ) ;
172+ }
155173 }
156174
157175 private void AppButton_OnClick ( object sender , RoutedEventArgs e )
0 commit comments