# 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](/api/wisej.web/interfaces/wisej.web.icommandsource.md) interface.

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

```csharp
public class ICommandSourceExtensions
```

{% endtab %}

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

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

{% endtab %}
{% endtabs %}

## Methods

### ![](/files/lIX317sDtMTZJBi9oSIx) Command\<TCommandSource>(button, value)

Sets the Command property of the specified [ICommandSource](/api/wisej.web/interfaces/wisej.web.icommandsource.md).

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

**Returns:** [TCommandSource](/api/wisej.web.markup/extensions/wisej.web.markup.icommandsourceextensions.md). 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());

```

### ![](/files/lIX317sDtMTZJBi9oSIx) OnCommandChanged\<TCommandSource>(button, action)

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

| Parameter          | Type                                                                                            | Description                                                                                                             |
| ------------------ | ----------------------------------------------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------- |
| **TCommandSource** |                                                                                                 | The type of the command source, must implement [ICommandSource](/api/wisej.web/interfaces/wisej.web.icommandsource.md). |
| **button**         | [TCommandSource](/api/wisej.web.markup/extensions/wisej.web.markup.icommandsourceextensions.md) | 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](/api/wisej.web.markup/extensions/wisej.web.markup.icommandsourceextensions.md). 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!");
});

```


---

# 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.markup/extensions/wisej.web.markup.icommandsourceextensions.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.
