/// <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;
        }
Example #2
0
        void ICommand.Execute(object parameter)
        {
            var target = DataContext.GetDataContext(_target);

            if (_target == null)
            {
                return;
            }

            bool canExecute;

            CommandExecutionManager.TryExecuteCommand(target, parameter, true, Executed, CanExecute, out canExecute);
        }
Example #3
0
        bool ICommand.CanExecute(object parameter)
        {
            var target = DataContext.GetDataContext(_target);

            if (_target == null)
            {
                return(false);
            }

            bool canExecute;

            return
                (CommandExecutionManager.TryExecuteCommand(target, parameter, false, Executed, CanExecute, out canExecute) &&
                 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;
            }
        }