@@ -137,6 +137,7 @@ public void Initialize()
137137 dockPanel . Children . Insert ( dockPanel . Children . Count - 2 , statusBar ) ;
138138
139139 Core . WinForms . MenuService . ExecuteCommand = ExecuteCommand ;
140+ Core . WinForms . MenuService . CanExecuteCommand = CanExecuteCommand ;
140141 UpdateMenu ( ) ;
141142
142143 AddHandler ( Hyperlink . RequestNavigateEvent , new RequestNavigateEventHandler ( OnRequestNavigate ) ) ;
@@ -160,9 +161,9 @@ void ExecuteCommand(ICommand command, object caller)
160161 {
161162 ServiceSingleton . GetRequiredService < IAnalyticsMonitor > ( )
162163 . TrackFeature ( command . GetType ( ) . FullName , "Menu" ) ;
163- var routedCommand = command as System . Windows . Input . RoutedCommand ;
164+ var routedCommand = command as RoutedCommand ;
164165 if ( routedCommand != null ) {
165- var target = System . Windows . Input . FocusManager . GetFocusedElement ( this ) ;
166+ var target = FocusManager . GetFocusedElement ( this ) ;
166167 if ( routedCommand . CanExecute ( caller , target ) )
167168 routedCommand . Execute ( caller , target ) ;
168169 } else {
@@ -171,6 +172,17 @@ void ExecuteCommand(ICommand command, object caller)
171172 }
172173 }
173174
175+ bool CanExecuteCommand ( ICommand command , object caller )
176+ {
177+ var routedCommand = command as RoutedCommand ;
178+ if ( routedCommand != null ) {
179+ var target = FocusManager . GetFocusedElement ( this ) ;
180+ return routedCommand . CanExecute ( caller , target ) ;
181+ } else {
182+ return command . CanExecute ( caller ) ;
183+ }
184+ }
185+
174186 // keep a reference to the event handler to prevent it from being garbage collected
175187 // (CommandManager.RequerySuggested only keeps weak references to the event handlers)
176188 EventHandler requerySuggestedEventHandler ;
0 commit comments