/// <summary> /// The method that is called when the PreviewCanExecute <see cref="RoutedEvent" /> for the /// <see cref="ICommand" /> associated with this <see cref="DataContextCommandBinding" /> /// should be handled. /// </summary> /// <param name="sender">The command target on which the command is executing.</param> /// <param name="e">The event data.</param> protected internal override void OnPreviewCanExecute(object sender, CanExecuteRoutedEventArgs e) { if (e == null) { throw new ArgumentNullException("e"); } var target = DataContext.GetDataContext(sender); bool canExecute; if ( !CommandExecutionManager.TryExecuteCommand( target, e.Parameter, false, PreviewExecuted, PreviewCanExecute, out canExecute)) { return; } e.CanExecute = canExecute; e.Handled = true; }
bool ICommand.CanExecute(object parameter) { var target = GetDataContext(this._target); if (this._target == null) { return(false); } bool canExecute; return(CommandExecutionManager.TryExecuteCommand(target, parameter, false, this.Executed, this.CanExecute, out canExecute) && canExecute); }
void ICommand.Execute(object parameter) { var target = GetDataContext(this._target); if (this._target == null) { return; } bool canExecute; CommandExecutionManager.TryExecuteCommand(target, parameter, true, this.Executed, this.CanExecute, out canExecute); }
/// <summary> /// The method that is called when the Executed <see cref="RoutedEvent" /> for the /// <see cref="ICommand" /> associated with this <see cref="DataContextCommandBinding" /> /// should be handled. /// </summary> /// <param name="sender">The command target on which the command is executing.</param> /// <param name="e">The event data.</param> protected internal override void OnExecuted(object sender, ExecutedRoutedEventArgs e) { if (e == null) { throw new ArgumentNullException("e"); } var target = DataContext.GetDataContext(sender); bool canExecute; if (CommandExecutionManager.TryExecuteCommand( target, e.Parameter, true, Executed, CanExecute, out canExecute)) { e.Handled = true; } }