Skip to main content
Version: 4.1

Command

Namespace: Wisej.Web

Assembly: Wisej.Framework (4.1.0.0)

Implements the ICommand interface wrapping execute and canExecute actions.

public class Command : ICommand

You can use this class and Command to wrap custom commands to bind to controls that implement the ICommandSource interface. A view model class can expose as many commands as you like. You can bind (or assign) a command to the Command property (see Command for example).


public CommandDemoViewModel : INotifyPropertyChanged
{
public event PropertyChangedEventHandler PropertyChanged;

public int Number { ... }

public Wisej.Web.ICommand AddCommand { get; }

public CommandDemoViewModel()
{
this.AddCommand = new Command(args => this.Number++);

// Or
this.AddCommand = new Command(
execute: args => this.Number++,
canExecute: args => this.Number < 10
);
}
}

Now you can use data binding or a code assignment to connect the view model's Add command to a button's Command property.

Constructors

Instance member Command(execute, canExecute)

Initializes a new Command wrapping an execute method and an canExecute method.

NameTypeDescription
executeActionInvoked by the ICommandSource to perform a command.
canExecuteFunc<Boolean>Invoked by the ICommandSource to determine whether it can execute the execute function.

Instance member Command(execute, canExecute)

Initializes a new Command wrapping an execute method and an canExecute method.

NameTypeDescription
executeAction<CommandArgs>Invoked by the ICommandSource to perform a command.
canExecuteFunc<CommandArgs, Boolean>Invoked by the ICommandSource to determine whether it can execute the execute function.

Methods

Instance member CanExecute(args)

Executes a method that determines whether the command can execute in its current state.

ParameterTypeDescription
argsCommandArgsA CommandArgs that contains data that can be used by the command.

Returns: Boolean. true if this command can be executed; otherwise, false.

Instance member Execute(args)

Executes the command method.

ParameterTypeDescription
argsCommandArgsA CommandArgs that contains data that can be used by the command.

Instance member RaiseCanExecuteChanged()

Fires the CanExecuteChanged event.

Events

Instance member CanExecuteChanged

EventHandler Fired when the result of the CanExecute method changes.

Inherited By

NameDescription
Command<T>Implements the ICommand interface wrapping execute and canExecute actions.

Implements

NameDescription
ICommandDefines a command that can be used for data binding.