2010-12-01 5 views
0

왜 명령 된 컨트롤이 항상 비활성화되어 있지만 명령을 실행할 수 있습니까? 명령이 설정이 컨트롤의 범위에서 명령에 대한 CommandBinding을가 없기 때문에 Alt + F4WPF 명령 문제

public static class CommandLibrary { 
    static CommandLibrary() { 
     ShutDownCommand = new RoutedUICommand("Exit", "Exit", typeof(CommandLibrary), new InputGestureCollection {new KeyGesture(Key.F4, ModifierKeys.Alt)}); 
    } 

    public static RoutedUICommand ShutDownCommand { get; private set; } 

    public static void BindCommands(Window hostWindow) { 
     if (hostWindow == null) 
      return; 

     hostWindow.CommandBindings.Add(new CommandBinding(ShutDownCommand, OnShutDownCommandExecuted, OnShutDownCommandCanExecute)); 
    } 

    private static void OnShutDownCommandExecuted(object sender, ExecutedRoutedEventArgs e) { 
     MessageBox.Show("ShutDown Excuted!"); 
    } 

    private static void OnShutDownCommandCanExecute(object sender, CanExecuteRoutedEventArgs e) { 
     e.CanExecute = true; 
    } 
} 

<MenuItem Command="local:CommandLibrary.ShutDownCommand" /> 

답변

1

보통 이런 일이 발생하여 명령도 실행됩니다. CanExecute 핸들러에 중단 점을 설정하면 MenuItem에 적중합니까?