0
왜 명령 된 컨트롤이 항상 비활성화되어 있지만 명령을 실행할 수 있습니까? 명령이 설정이 컨트롤의 범위에서 명령에 대한 CommandBinding을가 없기 때문에 Alt + F4
WPF 명령 문제
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" />