protected override void Invoke()

in src/Microsoft.Xaml.Behaviors/InvokeCommandAction.cs [110:147]


        protected override void Invoke(object parameter)
        {
            if (this.AssociatedObject != null)
            {
                ICommand command = this.ResolveCommand();

                if (command != null)
                {
                    object commandParameter = this.CommandParameter;

                    //if no CommandParameter has been provided, let's check the EventArgsParameterPath
                    if (commandParameter == null && !string.IsNullOrWhiteSpace(this.EventArgsParameterPath))
                    {
                        commandParameter = GetEventArgsPropertyPathValue(parameter);
                    }

                    //next let's see if an event args converter has been supplied
                    if (commandParameter == null && this.EventArgsConverter != null)
                    {
                        commandParameter = this.EventArgsConverter.Convert(parameter, typeof(object), EventArgsConverterParameter, CultureInfo.CurrentCulture);
                    }

                    //last resort, let see if they want to force the event args to be passed as a parameter
                    if (commandParameter == null && this.PassEventArgsToCommand)
                    {
                        commandParameter = parameter;
                    }

                    if (command.CanExecute(commandParameter))
                    {
                        command.Execute(commandParameter);
                    }
                } else
                {
                    Debug.WriteLine(ExceptionStringTable.CommandDoesNotExistOnBehaviorWarningMessage, this.CommandName, this.AssociatedObject.GetType().Name);
                }
            }
        }