DxButton Class

A Button component.

Namespace: DevExpress.Blazor

Assembly: DevExpress.Blazor.v20.2.dll

Declaration

public class DxButton :
    DxComponentBase<JSInteropProxyBase>,
    ISizeModeAccessor,
    IRequireSelfCascading

Remarks

The DevExpress Button for Blazor (<DxButton>) allows you to add a stylized button to your project and handle its click.

Button

Run Demo: Button

Add a Button to a Project

Follow the steps below to add the Button component to an application:

  1. Use a DevExpress Project Template to create a new Blazor Server or Blazor WebAssembly application. If you use a Microsoft project template or already have a Blazor project, configure your project to incorporate DevExpress Blazor components.
  2. Add the <DxButton/> markup to a Razor page.
  3. Configure the component (see the sections below).

Button Content and Appearance

Use the Text property to specify the button’s text.

To configure the button’s appearance, specify the RenderStyle and RenderStyleMode properties. All the Bootstrap styles are available.

<DxButton RenderStyle="ButtonRenderStyle.Primary" RenderStyleMode="ButtonRenderStyleMode.Contained" 
    Text="Primary (Contained)" />
<DxButton RenderStyle="ButtonRenderStyle.Danger" RenderStyleMode="ButtonRenderStyleMode.Outline" 
    Text="Danger (Outline)" />
<DxButton RenderStyle="ButtonRenderStyle.Link" RenderStyleMode="ButtonRenderStyleMode.Contained" 
    Text="Link" />

Button Styles

Assign the icon’s CSS class to the IconCssClass property to add an icon to your button. The IconPosition property specifies the icon position (before or after the text).

<DxButton RenderStyle="ButtonRenderStyle.Dark" Text="Undo" Title="Undo the last action." 
    IconCssClass="undo" style="margin-right: 0.5em;"/>
<DxButton RenderStyle="ButtonRenderStyle.Dark" Text="Redo" Title="Restore the previously undone action." 
    IconCssClass="redo" IconPosition="ButtonIconPosition.AfterText" />

Button with icons

To hide the button, set the Visible property to false.

Run Demo: Button — Icons

Size Modes

Use the SizeMode property to specify a button size. The code below applies different size modes to Button components.

<DxButton Text="Small" SizeMode="SizeMode.Small" />

<DxButton Text="Medium" SizeMode="SizeMode.Medium" />

<DxButton Text="Large" SizeMode="SizeMode.Large" />

For more information, refer to Size Modes.

Handle the Click Event

Handle the Click event to respond to the button’s click.

<DxButton ...
    Click="@Handler">

@code {
    // ...
    void Handler(MouseEventArgs args) {
        Console.WriteLine("I am clicked!");
    }
}

To use the button as a form submit, set the SubmitFormOnClick option to true.

Set the Enabled property to false to disable the button.

<DxButton RenderStyle="ButtonRenderStyle.Primary" Text="Disabled button" Enabled="false" />

Disabled Button

Custom Content

You can implement custom content for your button and customize the button’s appearance and behaviour.

Button Custom Content

<DxButton RenderStyle="ButtonRenderStyle.Info" Click="@Like" IconCssClass="like" Text="Like">
    @context
    <span style="width: 0.8em; margin-left: 8px;">@(likes < 10 ? likes.ToString() : "9")</span>
</DxButton>

@code {
    int likes;
    protected override void OnInitialized() {
        likes = 1;
    }
    void Like(DxButtonClickEventArgs args) {
        likes++;
    }
}

Run Demo: Button — Custom Content

Inheritance

Object
ComponentBase
DevExpress.Blazor.Base.DxAsyncDisposableComponent
DevExpress.Blazor.Base.DxDecoratedComponent
DxComponentBase
DxComponentBase<DevExpress.Blazor.Internal.JSInterop.JSInteropProxyBase>
DxButton
See Also