# ButtonExtensions

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 [ButtonBase](/api/wisej.web/buttons/wisej.web.buttonbase.md), [Button](/api/wisej.web/buttons/button.md) and [SplitButton](/api/wisej.web/buttons/wisej.web.splitbutton.md) classes.

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

```csharp
public class ButtonExtensions
```

{% endtab %}

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

```visual-basic
Public Class ButtonExtensions
```

{% endtab %}
{% endtabs %}

## Methods

### ![](/files/lIX317sDtMTZJBi9oSIx) AllowHtml\<TButtonBase>(button, value)

Sets the AllowHtml property of the specified [ButtonBase](/api/wisej.web/buttons/wisej.web.buttonbase.md).

| Parameter       | Type                                                                                 | Description                                                                                             |
| --------------- | ------------------------------------------------------------------------------------ | ------------------------------------------------------------------------------------------------------- |
| **TButtonBase** |                                                                                      | The type of the button, must inherit from [ButtonBase](/api/wisej.web/buttons/wisej.web.buttonbase.md). |
| **button**      | [TButtonBase](/api/wisej.web.markup/extensions/wisej.web.markup.buttonextensions.md) | The button for which to set the AllowHtml property.                                                     |
| **value**       | [Boolean](https://docs.microsoft.com/dotnet/api/system.boolean)                      | A boolean indicating whether HTML is allowed in the button's text.                                      |

**Returns:** [TButtonBase](/api/wisej.web.markup/extensions/wisej.web.markup.buttonextensions.md). The modified button with the updated AllowHtml property.

This method allows you to enable or disable HTML content in the button's text.

```csharp

myButton.AllowHtml(true);

```

### ![](/files/lIX317sDtMTZJBi9oSIx) AllowMarkdown\<TButtonBase>(button, value)

Sets the AllowMarkdown property of the specified [ButtonBase](/api/wisej.web/buttons/wisej.web.buttonbase.md).

| Parameter       | Type                                                                                 | Description                                                                                             |
| --------------- | ------------------------------------------------------------------------------------ | ------------------------------------------------------------------------------------------------------- |
| **TButtonBase** |                                                                                      | The type of the button, must inherit from [ButtonBase](/api/wisej.web/buttons/wisej.web.buttonbase.md). |
| **button**      | [TButtonBase](/api/wisej.web.markup/extensions/wisej.web.markup.buttonextensions.md) | The button for which to set the AllowMarkdown property.                                                 |
| **value**       | [Boolean](https://docs.microsoft.com/dotnet/api/system.boolean)                      | A boolean indicating whether Markdown is allowed in the button's text.                                  |

**Returns:** [TButtonBase](/api/wisej.web.markup/extensions/wisej.web.markup.buttonextensions.md). The modified button with the updated AllowMarkdown property.

This method allows you to enable or disable Markdown content in the button's text.

```csharp

myButton.AllowMarkdown(true);

```

### ![](/files/lIX317sDtMTZJBi9oSIx) AutoEllipsis\<TButtonBase>(button, value)

Sets the AutoEllipsis property of the specified [ButtonBase](/api/wisej.web/buttons/wisej.web.buttonbase.md).

| Parameter       | Type                                                                                 | Description                                                                                             |
| --------------- | ------------------------------------------------------------------------------------ | ------------------------------------------------------------------------------------------------------- |
| **TButtonBase** |                                                                                      | The type of the button, must inherit from [ButtonBase](/api/wisej.web/buttons/wisej.web.buttonbase.md). |
| **button**      | [TButtonBase](/api/wisej.web.markup/extensions/wisej.web.markup.buttonextensions.md) | The button for which to set the AutoEllipsis property.                                                  |
| **value**       | [Boolean](https://docs.microsoft.com/dotnet/api/system.boolean)                      | A boolean indicating whether to automatically show ellipses when text is truncated.                     |

**Returns:** [TButtonBase](/api/wisej.web.markup/extensions/wisej.web.markup.buttonextensions.md). The modified button with the updated AutoEllipsis property.

This method allows you to enable or disable the automatic display of ellipses when the button's text is truncated.

```csharp

myButton.AutoEllipsis(true);

```

### ![](/files/lIX317sDtMTZJBi9oSIx) AutoShowLoader\<TButtonBase>(button, value)

Sets the AutoShowLoader property of the specified [ButtonBase](/api/wisej.web/buttons/wisej.web.buttonbase.md).

| Parameter       | Type                                                                                 | Description                                                                                             |
| --------------- | ------------------------------------------------------------------------------------ | ------------------------------------------------------------------------------------------------------- |
| **TButtonBase** |                                                                                      | The type of the button, must inherit from [ButtonBase](/api/wisej.web/buttons/wisej.web.buttonbase.md). |
| **button**      | [TButtonBase](/api/wisej.web.markup/extensions/wisej.web.markup.buttonextensions.md) | The button for which to set the AutoShowLoader property.                                                |
| **value**       | [Boolean](https://docs.microsoft.com/dotnet/api/system.boolean)                      | A boolean indicating whether to automatically show a loader on the button.                              |

**Returns:** [TButtonBase](/api/wisej.web.markup/extensions/wisej.web.markup.buttonextensions.md). The modified button with the updated AutoShowLoader property.

This method allows you to enable or disable the automatic display of a loader on the button.

```csharp

myButton.AutoShowLoader(true);

```

### ![](/files/lIX317sDtMTZJBi9oSIx) AutoSizeMode\<TButton>(button, mode)

Sets the AutoSizeMode property of the specified [Button](/api/wisej.web/buttons/button.md).

| Parameter   | Type                                                                             | Description                                                                           |
| ----------- | -------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------- |
| **TButton** |                                                                                  | The type of the button, must inherit from [Button](/api/wisej.web/buttons/button.md). |
| **button**  | [TButton](/api/wisej.web.markup/extensions/wisej.web.markup.buttonextensions.md) | The button for which to set the AutoSizeMode property.                                |
| **mode**    | [AutoSizeMode](/api/wisej.web/enumerations/wisej.web.autosizemode.md)            | The [AutoSizeMode](#autosizemode``1) to set for the button.                           |

**Returns:** [TButton](/api/wisej.web.markup/extensions/wisej.web.markup.buttonextensions.md). The modified button with the updated AutoSizeMode property.

This method allows you to specify the automatic sizing behavior for the button.

```csharp

myButton.AutoSizeMode(AutoSizeMode.GrowAndShrink);

```

### ![](/files/lIX317sDtMTZJBi9oSIx) AutoToolTip\<TButton>(button, value)

Sets the AutoToolTip property of the specified [Button](/api/wisej.web/buttons/button.md).

| Parameter   | Type                                                                             | Description                                                                                                            |
| ----------- | -------------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------- |
| **TButton** |                                                                                  | The type of the button, must inherit from [Button](/api/wisej.web/buttons/button.md) and have an AutoToolTip property. |
| **button**  | [TButton](/api/wisej.web.markup/extensions/wisej.web.markup.buttonextensions.md) | The button for which to set the AutoToolTip property.                                                                  |
| **value**   | [Boolean](https://docs.microsoft.com/dotnet/api/system.boolean)                  | A boolean indicating whether tooltips are automatically shown for the button.                                          |

**Returns:** [TButton](/api/wisej.web.markup/extensions/wisej.web.markup.buttonextensions.md). The modified button with the updated AutoToolTip property.

This method allows you to enable or disable automatic tooltips for the button.

```csharp

myButton.AutoToolTip(true);

```

### ![](/files/lIX317sDtMTZJBi9oSIx) BorderStyle\<TButton>(button, borderStyle)

Sets the BorderStyle property of the specified [Button](/api/wisej.web/buttons/button.md).

| Parameter       | Type                                                                             | Description                                                                                                           |
| --------------- | -------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------------------------- |
| **TButton**     |                                                                                  | The type of the button, must inherit from [Button](/api/wisej.web/buttons/button.md) and have a BorderStyle property. |
| **button**      | [TButton](/api/wisej.web.markup/extensions/wisej.web.markup.buttonextensions.md) | The button for which to set the BorderStyle property.                                                                 |
| **borderStyle** | [BorderStyle](/api/wisej.web/enumerations/wisej.web.borderstyle.md)              | The [BorderStyle](#borderstyle``1) to set for the button.                                                             |

**Returns:** [TButton](/api/wisej.web.markup/extensions/wisej.web.markup.buttonextensions.md). The modified button with the updated BorderStyle property.

This method allows you to specify the border style for the button.

```csharp

myButton.BorderStyle(BorderStyle.FixedSingle);

```

### ![](/files/lIX317sDtMTZJBi9oSIx) CharacterCasing\<TButtonBase>(button, casing)

Sets the CharacterCasing property of the specified [ButtonBase](/api/wisej.web/buttons/wisej.web.buttonbase.md).

| Parameter       | Type                                                                                 | Description                                                                                             |
| --------------- | ------------------------------------------------------------------------------------ | ------------------------------------------------------------------------------------------------------- |
| **TButtonBase** |                                                                                      | The type of the button, must inherit from [ButtonBase](/api/wisej.web/buttons/wisej.web.buttonbase.md). |
| **button**      | [TButtonBase](/api/wisej.web.markup/extensions/wisej.web.markup.buttonextensions.md) | The button for which to set the CharacterCasing property.                                               |
| **casing**      | [CharacterCasing](/api/wisej.web/editors/wisej.web.charactercasing.md)               | The [CharacterCasing](#charactercasing``1) to set for the button text.                                  |

**Returns:** [TButtonBase](/api/wisej.web.markup/extensions/wisej.web.markup.buttonextensions.md). The modified button with the updated CharacterCasing property.

This method allows you to specify the character casing for the button's text.

```csharp

myButton.CharacterCasing(CharacterCasing.Upper);

```

### ![](/files/lIX317sDtMTZJBi9oSIx) Display\<TButton>(button, display)

Sets the Display property of the specified [Button](/api/wisej.web/buttons/button.md).

| Parameter   | Type                                                                             | Description                                                                                                       |
| ----------- | -------------------------------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------------- |
| **TButton** |                                                                                  | The type of the button, must inherit from [Button](/api/wisej.web/buttons/button.md) and have a Display property. |
| **button**  | [TButton](/api/wisej.web.markup/extensions/wisej.web.markup.buttonextensions.md) | The button for which to set the Display property.                                                                 |
| **display** | [Display](/api/wisej.web/enumerations/wisej.web.display.md)                      | The [Display](#display``1) setting to apply to the button.                                                        |

**Returns:** [TButton](/api/wisej.web.markup/extensions/wisej.web.markup.buttonextensions.md). The modified button with the updated Display property.

This method allows you to specify the display setting for the button.

```csharp

myButton.Display(Display.Standard);

```

### ![](/files/lIX317sDtMTZJBi9oSIx) ImageSpacing\<TButton>(button, spacing)

Sets the ImageSpacing property of the specified [Button](/api/wisej.web/buttons/button.md).

| Parameter   | Type                                                                             | Description                                                                                                             |
| ----------- | -------------------------------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------- |
| **TButton** |                                                                                  | The type of the button, must inherit from [Button](/api/wisej.web/buttons/button.md) and have an ImageSpacing property. |
| **button**  | [TButton](/api/wisej.web.markup/extensions/wisej.web.markup.buttonextensions.md) | The button for which to set the ImageSpacing property.                                                                  |
| **spacing** | [Nullable\<Int32>](https://docs.microsoft.com/dotnet/api/system.nullable-1)      | The spacing to set between the image and text on the button.                                                            |

**Returns:** [TButton](/api/wisej.web.markup/extensions/wisej.web.markup.buttonextensions.md). The modified button with the updated ImageSpacing property.

This method allows you to specify the spacing between the image and text on the button.

```csharp

myButton.ImageSpacing(10);

```

### ![](/files/lIX317sDtMTZJBi9oSIx) MenuItems\<TButton>(button, items)

Adds the specified menu items to the MenuItems collection of the specified [Button](/api/wisej.web/buttons/button.md).

| Parameter   | Type                                                                             | Description                                                                                                         |
| ----------- | -------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------- |
| **TButton** |                                                                                  | The type of the button, must inherit from [Button](/api/wisej.web/buttons/button.md) and have a MenuItems property. |
| **button**  | [TButton](/api/wisej.web.markup/extensions/wisej.web.markup.buttonextensions.md) | The button to which the menu items should be added.                                                                 |
| **items**   | [MenuItem\[\]](/api/wisej.web/menus/wisej.web.menuitem.md)                       | An array of [MenuItem](/api/wisej.web/menus/wisej.web.menuitem.md) to add to the button.                            |

**Returns:** [TButton](/api/wisej.web.markup/extensions/wisej.web.markup.buttonextensions.md). The modified button with the added menu items.

This method allows you to add multiple menu items to the button in one call.

```csharp

myButton.MenuItems(new MenuItem("Item1"), new MenuItem("Item2"));

```

### ![](/files/lIX317sDtMTZJBi9oSIx) OnItemClicked\<TButton>(button, action)

Attaches an event handler for the ItemClicked event of the specified [Button](/api/wisej.web/buttons/button.md).

| Parameter   | Type                                                                                                      | Description                                                                                                         |
| ----------- | --------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------- |
| **TButton** |                                                                                                           | The type of the button, must inherit from [Button](/api/wisej.web/buttons/button.md) and have an ItemClicked event. |
| **button**  | [TButton](/api/wisej.web.markup/extensions/wisej.web.markup.buttonextensions.md)                          | The button to attach the event handler to.                                                                          |
| **action**  | [Action\<TButton, MenuButtonItemClickedEventArgs>](https://docs.microsoft.com/dotnet/api/system.action-2) | An action to execute when an item is clicked.                                                                       |

**Returns:** [TButton](/api/wisej.web.markup/extensions/wisej.web.markup.buttonextensions.md). The modified button with the attached ItemClicked event handler.

This method allows you to execute a custom action whenever an item within the button's menu is clicked.

```csharp

myButton.OnItemClicked((btn, args) =>
{
AlertBox.Show("Item clicked!");
});

```

### ![](/files/lIX317sDtMTZJBi9oSIx) OnMenuCollapse\<TButton>(button, action)

Attaches an event handler for the MenuCollapse event of the specified [Button](/api/wisej.web/buttons/button.md).

| Parameter   | Type                                                                             | Description                                                                                                         |
| ----------- | -------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------- |
| **TButton** |                                                                                  | The type of the button, must inherit from [Button](/api/wisej.web/buttons/button.md) and have a MenuCollapse event. |
| **button**  | [TButton](/api/wisej.web.markup/extensions/wisej.web.markup.buttonextensions.md) | The button to attach the event handler to.                                                                          |
| **action**  | [Action\<TButton>](https://docs.microsoft.com/dotnet/api/system.action-1)        | An action to execute when the menu collapses.                                                                       |

**Returns:** [TButton](/api/wisej.web.markup/extensions/wisej.web.markup.buttonextensions.md). The modified button with the attached MenuCollapse event handler.

This method allows you to execute a custom action whenever the button's menu collapses.

```csharp

myButton.OnMenuCollapse(btn =>
{
AlertBox.Show("Menu collapsed!");
});

```

### ![](/files/lIX317sDtMTZJBi9oSIx) OnMenuPopup\<TButton>(button, action)

Attaches an event handler for the MenuPopup event of the specified [Button](/api/wisej.web/buttons/button.md).

| Parameter   | Type                                                                             | Description                                                                                                      |
| ----------- | -------------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------- |
| **TButton** |                                                                                  | The type of the button, must inherit from [Button](/api/wisej.web/buttons/button.md) and have a MenuPopup event. |
| **button**  | [TButton](/api/wisej.web.markup/extensions/wisej.web.markup.buttonextensions.md) | The button to attach the event handler to.                                                                       |
| **action**  | [Action\<TButton>](https://docs.microsoft.com/dotnet/api/system.action-1)        | An action to execute when the menu pops up.                                                                      |

**Returns:** [TButton](/api/wisej.web.markup/extensions/wisej.web.markup.buttonextensions.md). The modified button with the attached MenuPopup event handler.

This method allows you to execute a custom action whenever the button's menu pops up.

```csharp

myButton.OnMenuPopup(btn =>
{
AlertBox.Show("Menu popped up!");
});

```

### ![](/files/lIX317sDtMTZJBi9oSIx) Orientation\<TSplitButton>(button, orientation)

Sets the Orientation property of the specified [SplitButton](/api/wisej.web/buttons/wisej.web.splitbutton.md).

| Parameter        | Type                                                                                  | Description                                                                                               |
| ---------------- | ------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------------- |
| **TSplitButton** |                                                                                       | The type of the button, must inherit from [SplitButton](/api/wisej.web/buttons/wisej.web.splitbutton.md). |
| **button**       | [TSplitButton](/api/wisej.web.markup/extensions/wisej.web.markup.buttonextensions.md) | The split button for which to set the Orientation property.                                               |
| **orientation**  | [Orientation](/api/wisej.web/enumerations/wisej.web.orientation.md)                   | The [Orientation](#orientation``1) to set for the button.                                                 |

**Returns:** [TSplitButton](/api/wisej.web.markup/extensions/wisej.web.markup.buttonextensions.md). The modified button with the updated Orientation property.

This method allows you to specify the orientation of the split button, such as horizontal or vertical.

```csharp

mySplitButton.Orientation(Orientation.Horizontal);

```

### ![](/files/lIX317sDtMTZJBi9oSIx) Repeat\<TButton>(button, value)

Sets the Repeat property of the specified [Button](/api/wisej.web/buttons/button.md).

| Parameter   | Type                                                                             | Description                                                                                                      |
| ----------- | -------------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------- |
| **TButton** |                                                                                  | The type of the button, must inherit from [Button](/api/wisej.web/buttons/button.md) and have a Repeat property. |
| **button**  | [TButton](/api/wisej.web.markup/extensions/wisej.web.markup.buttonextensions.md) | The button for which to set the Repeat property.                                                                 |
| **value**   | [Boolean](https://docs.microsoft.com/dotnet/api/system.boolean)                  | A boolean indicating whether the button repeats its action when held down.                                       |

**Returns:** [TButton](/api/wisej.web.markup/extensions/wisej.web.markup.buttonextensions.md). The modified button with the updated Repeat property.

This method allows you to enable or disable repeating actions for the button when it is held down.

```csharp

myButton.Repeat(true);

```

### ![](/files/lIX317sDtMTZJBi9oSIx) Shortcut\<TButton>(button, shortcut)

Sets the Shortcut property of the specified [Button](/api/wisej.web/buttons/button.md).

| Parameter    | Type                                                                             | Description                                                                                                        |
| ------------ | -------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------ |
| **TButton**  |                                                                                  | The type of the button, must inherit from [Button](/api/wisej.web/buttons/button.md) and have a Shortcut property. |
| **button**   | [TButton](/api/wisej.web.markup/extensions/wisej.web.markup.buttonextensions.md) | The button for which to set the Shortcut property.                                                                 |
| **shortcut** | [Shortcut](/api/wisej.web/enumerations/wisej.web.shortcut.md)                    | The [Shortcut](#shortcut``1) to set for the button.                                                                |

**Returns:** [TButton](/api/wisej.web.markup/extensions/wisej.web.markup.buttonextensions.md). The modified button with the updated Shortcut property.

This method allows you to specify a keyboard shortcut for the button.

```csharp

myButton.Shortcut(Shortcut.CtrlS);

```

### ![](/files/lIX317sDtMTZJBi9oSIx) TextAlign\<TButtonBase>(button, alignment)

Sets the TextAlign property of the specified [ButtonBase](/api/wisej.web/buttons/wisej.web.buttonbase.md).

| Parameter       | Type                                                                                      | Description                                                                                                               |
| --------------- | ----------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------- |
| **TButtonBase** |                                                                                           | The type of the button, must inherit from [ButtonBase](/api/wisej.web/buttons/wisej.web.buttonbase.md).                   |
| **button**      | [TButtonBase](/api/wisej.web.markup/extensions/wisej.web.markup.buttonextensions.md)      | The button for which to set the TextAlign property.                                                                       |
| **alignment**   | [ContentAlignment](https://docs.microsoft.com/dotnet/api/system.drawing.contentalignment) | The [ContentAlignment](https://docs.microsoft.com/dotnet/api/system.drawing.contentalignment) to set for the button text. |

**Returns:** [TButtonBase](/api/wisej.web.markup/extensions/wisej.web.markup.buttonextensions.md). The modified button with the updated TextAlign property.

This method allows you to specify the alignment of the text on the button.

```csharp

myButton.TextAlign(ContentAlignment.MiddleCenter);

```

### ![](/files/lIX317sDtMTZJBi9oSIx) TextImageRelation\<TButtonBase>(button, textImageRelation)

Sets the TextImageRelation property of the specified [ButtonBase](/api/wisej.web/buttons/wisej.web.buttonbase.md).

| Parameter             | Type                                                                                 | Description                                                                                             |
| --------------------- | ------------------------------------------------------------------------------------ | ------------------------------------------------------------------------------------------------------- |
| **TButtonBase**       |                                                                                      | The type of the button, must inherit from [ButtonBase](/api/wisej.web/buttons/wisej.web.buttonbase.md). |
| **button**            | [TButtonBase](/api/wisej.web.markup/extensions/wisej.web.markup.buttonextensions.md) | The button for which to set the TextImageRelation property.                                             |
| **textImageRelation** | [TextImageRelation](/api/wisej.web/enumerations/wisej.web.textimagerelation.md)      | The [TextImageRelation](#textimagerelation``1) to set for the button.                                   |

**Returns:** [TButtonBase](/api/wisej.web.markup/extensions/wisej.web.markup.buttonextensions.md). The modified button with the updated TextImageRelation property.

This method allows you to specify the relationship between the button's text and image.

```csharp

myButton.TextImageRelation(TextImageRelation.ImageBeforeText);

```

### ![](/files/lIX317sDtMTZJBi9oSIx) UseMnemonic\<TButtonBase>(button, value)

Sets the UseMnemonic property of the specified [ButtonBase](/api/wisej.web/buttons/wisej.web.buttonbase.md).

| Parameter       | Type                                                                                 | Description                                                                                             |
| --------------- | ------------------------------------------------------------------------------------ | ------------------------------------------------------------------------------------------------------- |
| **TButtonBase** |                                                                                      | The type of the button, must inherit from [ButtonBase](/api/wisej.web/buttons/wisej.web.buttonbase.md). |
| **button**      | [TButtonBase](/api/wisej.web.markup/extensions/wisej.web.markup.buttonextensions.md) | The button for which to set the UseMnemonic property.                                                   |
| **value**       | [Boolean](https://docs.microsoft.com/dotnet/api/system.boolean)                      | A boolean indicating whether mnemonic characters are used.                                              |

**Returns:** [TButtonBase](/api/wisej.web.markup/extensions/wisej.web.markup.buttonextensions.md). The modified button with the updated UseMnemonic property.

This method allows you to enable or disable the use of mnemonic characters in the button's text.

```csharp

myButton.UseMnemonic(true);

```


---

# 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.buttonextensions.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.
