-2

次のような削除コマンドを実行したい:

ApplicationCommands.Delete.Execute(Keyboard.FocusedElement, Keyboard.FocusedElement);

しかし:

ApplicationCommands.Delete.CanExecute(Keyboard.FocusedElement, Keyboard.FocusedElement)

は false であるため、実行されません。

どうすればそれを真に変えることができますか?

4

1 に答える 1

1

CommandBindingExecute 関数と CanExecute 関数が呼び出されたときに何が起こるかを指定する sを設定する必要があると思います。

次に例を示します。

<Window x:Class="Window1"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
    <Window.CommandBindings>
        <CommandBinding Command="ApplicationCommands.Delete"
                        Executed="DeleteCommandHandler"
                        CanExecute="DeleteCanExecuteHandler" />
    </Window.CommandBindings>
    <StackPanel Name="MainStackPanel">
        <Button Command="ApplicationCommands.Delete" 
                Content="Delete File" />
    </StackPanel>
</Window>

この例は、CommandBindingのドキュメント (わずかに変更されています) からのものです。

于 2013-01-15T19:27:59.630 に答える