命令源在命令绑定的范围内向命令目标发送命令,但是当命令源不在命令绑定范围内的时候,命令绑定的附加事件是如何传送的呢?请大侠们帮我看一下下面代码附加事件的传送过程是什么样的?是怎么从命令源传到命令目标的?
还有在命令目标不由程序员指定的时候,不应该是当前焦点所在为命令目标吗,为什么添加监视中的命令目标为空呢?
xaml代码如下:
.cs代码如下:
public RoutedCommand clearCmd = new RoutedCommand("Clear", typeof(CommandWindow));
private void InitializeCommand()
{
this.button1.Command = this.clearCmd;
this.clearCmd.InputGestures.Add(new KeyGesture(Key.C, ModifierKeys.Alt));
this.button1.CommandTarget = this.textBoxA;
CommandBinding cb = new CommandBinding();
cb.Command = this.clearCmd;
cb.CanExecute += new CanExecuteRoutedEventHandler(cb_CanExecute);
cb.Executed += new ExecutedRoutedEventHandler(cb_Executed);
this.stackPanel2.CommandBindings.Add(cb);
}
void cb_CanExecute(object sender, CanExecuteRoutedEventArgs e)
{
if (string.IsNullOrEmpty(this.textBoxA.Text))
{
e.CanExecute = false;
}
else
{ e.CanExecute = true; }
e.Handled = true;
}
void cb_Executed(object sender, ExecutedRoutedEventArgs e)
{
this.textBoxA.Clear();
e.Handled = true;
}