# ICommandSourceExtensions

Namespace: **Wisej.Web.Markup**

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

Adds [fluent markup](https://learn.microsoft.com/en-us/dotnet/communitytoolkit/maui/markup/markup) extension methods to the [ICommandSource](https://docs.wisej.com/api/wisej.web/interfaces/wisej.web.icommandsource) interface.

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

```csharp
public class ICommandSourceExtensions
```

{% endtab %}

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

```visual-basic
Public Class ICommandSourceExtensions
```

{% endtab %}
{% endtabs %}

## Methods

### ![](https://1075938901-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F2HvlWXJQMV7DxhGzw7Y1%2Fuploads%2Fgit-blob-e4f8ed47a52590951f725a10c269555e81d41d81%2Fstatic.png?alt=media) Command\<TCommandSource>(button, value)

Sets the Command property of the specified [ICommandSource](https://docs.wisej.com/api/wisej.web/interfaces/wisej.web.icommandsource).

| Parameter          | Type                                                                                                               | Description                                                                                                                                |
| ------------------ | ------------------------------------------------------------------------------------------------------------------ | ------------------------------------------------------------------------------------------------------------------------------------------ |
| **TCommandSource** |                                                                                                                    | The type of the command source, must implement [ICommandSource](https://docs.wisej.com/api/wisej.web/interfaces/wisej.web.icommandsource). |
| **button**         | [TCommandSource](https://docs.wisej.com/api/wisej.web.markup/extensions/wisej.web.markup.icommandsourceextensions) | The command source for which to set the Command property.                                                                                  |
| **value**          | [ICommand](https://docs.wisej.com/api/wisej.web/interfaces/wisej.web.icommand)                                     | The [ICommand](https://docs.wisej.com/api/wisej.web/interfaces/wisej.web.icommand) to associate with the command source.                   |

**Returns:** [TCommandSource](https://docs.wisej.com/api/wisej.web.markup/extensions/wisej.web.markup.icommandsourceextensions). The modified command source with the updated Command property.

This method allows you to associate a command with the command source, enabling command-based interactions.

```csharp

myCommandSource.Command(new RelayCommand());

```

### ![](https://1075938901-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F2HvlWXJQMV7DxhGzw7Y1%2Fuploads%2Fgit-blob-e4f8ed47a52590951f725a10c269555e81d41d81%2Fstatic.png?alt=media) OnCommandChanged\<TCommandSource>(button, action)

Attaches an event handler for the CommandChanged event of the specified [ICommandSource](https://docs.wisej.com/api/wisej.web/interfaces/wisej.web.icommandsource).

| Parameter          | Type                                                                                                               | Description                                                                                                                                |
| ------------------ | ------------------------------------------------------------------------------------------------------------------ | ------------------------------------------------------------------------------------------------------------------------------------------ |
| **TCommandSource** |                                                                                                                    | The type of the command source, must implement [ICommandSource](https://docs.wisej.com/api/wisej.web/interfaces/wisej.web.icommandsource). |
| **button**         | [TCommandSource](https://docs.wisej.com/api/wisej.web.markup/extensions/wisej.web.markup.icommandsourceextensions) | The command source to attach the event handler to.                                                                                         |
| **action**         | [Action\<TCommandSource>](https://docs.microsoft.com/dotnet/api/system.action-1)                                   | An action to execute when the command changes.                                                                                             |

**Returns:** [TCommandSource](https://docs.wisej.com/api/wisej.web.markup/extensions/wisej.web.markup.icommandsourceextensions). The modified command source with the attached CommandChanged event handler.

This method allows you to execute a custom action whenever the command associated with the command source changes.

```csharp

myCommandSource.OnCommandChanged(cs =>
{
AlertBox.Show("Command changed!");
});

```
