Catel.MVVM.CommandManager.ExecuteCommand C# (CSharp) Méthode

ExecuteCommand() public méthode

Executes the command.
The is null or whitespace. The specified command is not created using the method.
public ExecuteCommand ( string commandName ) : void
commandName string Name of the command.
Résultat void
        public void ExecuteCommand(string commandName)
        {
            Argument.IsNotNullOrWhitespace("commandName", commandName);

            lock (_lockObject)
            {
                Log.Debug("Executing command '{0}'", commandName);

                if (!_commands.ContainsKey(commandName))
                {
                    throw Log.ErrorAndCreateException<InvalidOperationException>("Command '{0}' is not yet created using the CreateCommand method", commandName);
                }

                _commands[commandName].Execute(null);
            }
        }

Usage Example

            public void DoesNotExecuteUnregisteredCommands()
            {
                var vm = new CompositeCommandViewModel();
                var commandManager = new CommandManager();

                commandManager.CreateCommand("MyCommand");
                commandManager.RegisterCommand("MyCommand", vm.TestCommand1);

                Assert.IsTrue(commandManager.IsCommandCreated("MyCommand"));

                commandManager.UnregisterCommand("MyCommand", vm.TestCommand1);

                commandManager.ExecuteCommand("MyCommand");

                Assert.IsFalse(vm.IsTestCommand1Executed);
            }
All Usage Examples Of Catel.MVVM.CommandManager::ExecuteCommand