Catel.MVVM.CompositeCommand.RegisterCommand C# (CSharp) Method

RegisterCommand() public method

Registers the specified command.
Note that if the view model is not specified, the command must be unregistered manually in order to prevent memory leaks.
The is null.
public RegisterCommand ( ICommand command, IViewModel viewModel = null ) : void
command ICommand The command.
viewModel IViewModel The view model. If specified, the command will automatically be unregistered when the view model is closed.
return void
        public void RegisterCommand(ICommand command, IViewModel viewModel = null)
        {
            Argument.IsNotNull("command", command);

            lock (_lock)
            {
                var commandInfo = new CommandInfo(this, command, viewModel);

                _commandInfo.Add(commandInfo);
                command.CanExecuteChanged += OnCommandCanExecuteChanged;

                Log.Debug("Registered command in CompositeCommand");
            }
        }

Usage Example

Esempio n. 1
0
            public void PreventsExecutionOfPartiallyExecutableCommand(bool checkCanExecuteOfAllCommandsToDetermineCanExecuteForCompositeCommand, bool expectedValue)
            {
                var compositeCommand = new CompositeCommand();

                compositeCommand.RegisterCommand(new Command(() => { }, () => false));
                compositeCommand.RegisterCommand(new Command(() => { }, () => true));

                compositeCommand.CheckCanExecuteOfAllCommandsToDetermineCanExecuteForCompositeCommand = checkCanExecuteOfAllCommandsToDetermineCanExecuteForCompositeCommand;

                Assert.AreEqual(expectedValue, ((ICatelCommand)compositeCommand).CanExecute(null));
            }
All Usage Examples Of Catel.MVVM.CompositeCommand::RegisterCommand