arrow-left

All pages
gitbookPowered by GitBook
1 of 1

Loading...

Command<T>

Wisej.Web.Command<T>

Namespace: Wisej.Web

Assembly: Wisej.Framework (4.0.0.0)

  • Command

Implements the interface wrapping execute and canExecute actions.

You can use this class to wrap custom commands to bind to controls that implement the 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 property.

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

hashtag
Parameters

Name
Description

hashtag
Constructors

hashtag
Command(execute, canExecute)

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

Name
Type
Description

hashtag
Implements

Name
Description

T

The Type of the data passed to the actions.

execute

Action<CommandArgs<T>>arrow-up-right

Invoked by the ICommandSource to perform a command.

canExecute

Func<CommandArgs<T>, Boolean>arrow-up-right

Invoked by the ICommandSource to determine whether it can execute the execute function.

ICommand

Defines a command that can be used for data binding.

Public Class Command(Of T)
    Inherits Command
Command<T>
ICommand
ICommandSource
DataItem
Command
Command
public class Command<T> : Command

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