我想要一個窗口級別的KeyBinding命令參數作爲窗口本身。輸入綁定CommandParameter綁定到窗口
例如
<KeyBinding Command="{Binding CloseCommand}" CommandParameter="{Binding ElementName=mainWindow}" Key="Esc"/>
綁定工作,但參數爲空。什麼是工作?
以下是我的命令:`
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; }
}
你正在使用什麼樣的'Command'? – Peter
你的'Window'是否有一個名字,你的命令是怎樣的?而且因爲我是史努比:你爲什麼要用這個窗口作爲參數?你想做什麼? –