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

UnregisterCommand() public méthode

Unregisters a command with the specified command name.
The is null or whitespace. The is null. The specified command is not created using the method.
public UnregisterCommand ( string commandName, ICommand command ) : void
commandName string Name of the command.
command ICommand The command.
Résultat void
        public void UnregisterCommand(string commandName, ICommand command)
        {
            Argument.IsNotNullOrWhitespace("commandName", commandName);
            Argument.IsNotNull("command", command);

            if (CatelEnvironment.IsInDesignMode)
            {
                return;
            }

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

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

                _commands[commandName].UnregisterCommand(command);

                InvalidateCommands();
            }
        }

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);
            }