# Command

Namespace: **Wisej.Web**

Assembly: **Wisej.Framework** (4.0.0.0)

Implements the [ICommand](/api/wisej.web/interfaces/wisej.web.icommand.md) interface wrapping execute and canExecute actions.

{% tabs %}
{% tab title="C#" %}

```csharp
public class Command : ICommand
```

{% endtab %}

{% tab title="VB.NET" %}

```visual-basic
Public Class Command
    Inherits ICommand
```

{% endtab %}
{% endtabs %}

You can use this class and [Command](/api/wisej.web/data-binding/wisej.web.command.md) to wrap custom commands to bind to controls that implement the [ICommandSource](/api/wisej.web/interfaces/wisej.web.icommandsource.md) interface. A view model class can expose as many commands as you like. You can bind (or assign) a command to the [Command](/api/wisej.web/interfaces/wisej.web.icommandsource.md#command) property (see [Command](/api/wisej.web/buttons/wisej.web.buttonbase.md#command) for example).

```csharp

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](/api/wisej.web/buttons/wisej.web.buttonbase.md#command) property.

## Constructors

### ![](/files/hsR4ok3152WyAf8J2C1u) Command(execute, canExecute)

Initializes a new [Command](/api/wisej.web/data-binding/wisej.web.command.md) wrapping an *execute* method and an *canExecute* method.

| Name           | Type                                                                  | Description                                                                                                                                        |
| -------------- | --------------------------------------------------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------- |
| **execute**    | [Action](https://docs.microsoft.com/dotnet/api/system.action)         | Invoked by the [ICommandSource](/api/wisej.web/interfaces/wisej.web.icommandsource.md) to perform a command.                                       |
| **canExecute** | [Func\<Boolean>](https://docs.microsoft.com/dotnet/api/system.func-1) | Invoked by the [ICommandSource](/api/wisej.web/interfaces/wisej.web.icommandsource.md) to determine whether it can execute the *execute* function. |

### ![](/files/hsR4ok3152WyAf8J2C1u) Command(execute, canExecute)

Initializes a new [Command](/api/wisej.web/data-binding/wisej.web.command.md) wrapping an *execute* method and an *canExecute* method.

| Name           | Type                                                                               | Description                                                                                                                                        |
| -------------- | ---------------------------------------------------------------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------- |
| **execute**    | [Action\<CommandArgs>](https://docs.microsoft.com/dotnet/api/system.action-1)      | Invoked by the [ICommandSource](/api/wisej.web/interfaces/wisej.web.icommandsource.md) to perform a command.                                       |
| **canExecute** | [Func\<CommandArgs, Boolean>](https://docs.microsoft.com/dotnet/api/system.func-2) | Invoked by the [ICommandSource](/api/wisej.web/interfaces/wisej.web.icommandsource.md) to determine whether it can execute the *execute* function. |

## Methods

### ![](/files/hsR4ok3152WyAf8J2C1u) CanExecute(args)

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

| Parameter | Type                                                                | Description                                                                                                               |
| --------- | ------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------- |
| **args**  | [CommandArgs](/api/wisej.web/data-binding/wisej.web.commandargs.md) | A [CommandArgs](/api/wisej.web/data-binding/wisej.web.commandargs.md) that contains data that can be used by the command. |

**Returns:** [Boolean](https://docs.microsoft.com/dotnet/api/system.boolean). true if this command can be executed; otherwise, false.

### ![](/files/hsR4ok3152WyAf8J2C1u) Execute(args)

Executes the command method.

| Parameter | Type                                                                | Description                                                                                                               |
| --------- | ------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------- |
| **args**  | [CommandArgs](/api/wisej.web/data-binding/wisej.web.commandargs.md) | A [CommandArgs](/api/wisej.web/data-binding/wisej.web.commandargs.md) that contains data that can be used by the command. |

### ![](/files/hsR4ok3152WyAf8J2C1u) RaiseCanExecuteChanged()

Fires the [CanExecuteChanged](#canexecutechanged) event.

## Events

### ![](/files/hsR4ok3152WyAf8J2C1u) CanExecuteChanged

[EventHandler](https://docs.microsoft.com/dotnet/api/system.eventhandler) Fired when the result of the [CanExecute](#canexecute-args) method changes.

## Inherited By

| Name                                                                                     | Description                                                                                                                   |
| ---------------------------------------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------- |
| [Command\<T>](/api/wisej.web/data-binding/wisej.web.command-less-than-t-greater-than.md) | Implements the [ICommand](/api/wisej.web/interfaces/wisej.web.icommand.md) interface wrapping execute and canExecute actions. |

## Implements

| Name                                                        | Description                                          |
| ----------------------------------------------------------- | ---------------------------------------------------- |
| [ICommand](/api/wisej.web/interfaces/wisej.web.icommand.md) | Defines a command that can be used for data binding. |


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.wisej.com/api/wisej.web/data-binding/wisej.web.command.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
