質問

なぜコマンドコントロールが常に無効になっているのかコマンドは実行できますか?コマンドも実行されます Alt + F4

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" />
役に立ちましたか?

解決

通常、これはコントロールの範囲内にコマンドが設定されているコマンドのコマンドバインディングがないために発生します。 Canexecuteハンドラーにブレークポイントを設定した場合、Menuitemにヒットしますか?

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top