Catel.MVVM.CommandManager.CreateCommand C# (CSharp) Метод

CreateCommand() публичный Метод

Creates the command inside the command manager. If the throwExceptionWhenCommandIsAlreadyCreated is false and the command is already created, only the input gesture is updated for the existing command.
The is null or whitespace. The specified command is already created using the method.
public CreateCommand ( string commandName, Catel.Windows.Input.InputGesture inputGesture = null, ICompositeCommand compositeCommand = null, bool throwExceptionWhenCommandIsAlreadyCreated = true ) : void
commandName string Name of the command.
inputGesture Catel.Windows.Input.InputGesture The input gesture.
compositeCommand ICompositeCommand The composite command. If null, this will default to a new instance of .
throwExceptionWhenCommandIsAlreadyCreated bool if set to true, this method will throw an exception when the command is already created.
Результат void
        public void CreateCommand(string commandName, InputGesture inputGesture = null, ICompositeCommand compositeCommand = null,
            bool throwExceptionWhenCommandIsAlreadyCreated = true)
        {
            Argument.IsNotNullOrWhitespace("commandName", commandName);

            lock (_lockObject)
            {
                Log.Debug("Creating command '{0}' with input gesture '{1}'", commandName, ObjectToStringHelper.ToString(inputGesture));

                if (_commands.ContainsKey(commandName))
                {
                    var error = $"Command '{commandName}' is already created using the CreateCommand method";
                    Log.Error(error);

                    if (throwExceptionWhenCommandIsAlreadyCreated)
                    {
                        throw new InvalidOperationException(error);
                    }

                    _commandGestures[commandName] = inputGesture;
                    return;
                }

                if (compositeCommand == null)
                {
                    compositeCommand = new CompositeCommand();
                }

                _commands.Add(commandName, compositeCommand);
                _originalCommandGestures.Add(commandName, inputGesture);
                _commandGestures.Add(commandName, inputGesture);

                CommandCreated.SafeInvoke(this, () => new CommandCreatedEventArgs(compositeCommand, commandName));
            }
        }
#else

Same methods

CommandManager::CreateCommand ( string commandName, ICompositeCommand compositeCommand = null, bool throwExceptionWhenCommandIsAlreadyCreated = true ) : void

Usage Example

Пример #1
0
            public void ThrowsInvalidOperationExceptionForAlreadyCreatedCommand()
            {
                var commandManager = new CommandManager();

                commandManager.CreateCommand("MyCommand");

                ExceptionTester.CallMethodAndExpectException<InvalidOperationException>(() => commandManager.CreateCommand("MyCommand"));
            }
All Usage Examples Of Catel.MVVM.CommandManager::CreateCommand