Skip to main content
Version: 3.5

Command<T>

Namespace: Wisej.Web

Assembly: Wisej.Framework (3.5.0.0)

Implements the ICommand interface wrapping execute and canExecute actions.

public class Command<T> : Command

You can use this class to wrap custom commands to bind to controls that implement the ICommandSource interface and need to access the typed data source records. In the snippet below, the CommandDemoViewModel class derives from BindingList<Customer> and allows the commands to directly interact with the typed DataItem property.


public CommandDemoViewModel : BindingList<Person>
{

public Wisej.Web.ICommand SaveCommand { get; }

public CommandDemoViewModel()
{
this.SaveCommand = new Command<Person>(
execute: args => {
DB.Save(args.DataItem);
},
canExecute: args => {
return args.DataItem.Name != null &&
args.DataItem.Age > 0;
});
}
}

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

Parameters

NameDescription
TThe Type of the data passed to the actions.

Constructors

Instance memberCommand(execute, canExecute)

Initializes a new instance of Command.

NameTypeDescription
executeAction<CommandArgs<T>>
canExecuteFunc<CommandArgs<T>, Boolean>

Implements

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