ウィンドウレベルのKeyBindingをコマンドパラメータでウィンドウ自体として使用したいと考えています。入力バインディングCommandParameterウィンドウにバインド
<KeyBinding Command="{Binding CloseCommand}" CommandParameter="{Binding ElementName=mainWindow}" Key="Esc"/>
バインディングは機能しますが、パラメータはnullになります。何が回避策ですか?続き
は私のコマンドです: `
public class DelegateCommand : ICommand
{
private readonly Predicate<object> _canExecute;
private readonly Action<object> _execute;
public DelegateCommand(Action<object> execute)
: this(execute, null)
{
}
public DelegateCommand(Action<object> execute,
Predicate<object> canExecute)
{
if (execute == null)
throw new ArgumentNullException("Action excute is null");
_execute = execute;
_canExecute = canExecute;
}
[DebuggerStepThrough]
public bool CanExecute(object parameter)
{
return _canExecute == null ? true : _canExecute(parameter);
}
public void Execute(object parameter)
{
_execute(parameter);
}
public event EventHandler CanExecuteChanged
{
add { CommandManager.RequerySuggested += value; }
remove { CommandManager.RequerySuggested -= value; }
}
あなたはどのような 'コマンド 'を使用していますか? – Peter
あなたの 'Window'には名前があり、あなたのコマンドはどのように見えますか?私はスヌーピーだから、なぜあなたはパラメータとしてウィンドウを使いたいのですか?あなたは何をしたいですか? –