blazor-devexpress-dot-blazor-3ddff18e.md
A button control that supports advanced style and content customization options.
Namespace : DevExpress.Blazor
Assembly : DevExpress.Blazor.v25.2.dll
NuGet Package : DevExpress.Blazor
public class DxButton :
DxButtonBase
The DevExpress Button for Blazor (<DxButton>) allows you to add a stylized button to your project and handle its click.
Follow the steps below to add the Button component to an application:
<DxButton/> markup to a .razor file.Refer to the following list for the component API reference: DxButton Members.
Blazor Button does not support static render mode. Enable interactivity to use the component in your application. Refer to the following topic for more details: Enable Interactive Render Mode.
Use the Text property to specify the button’s text.
To configure button appearance, specify the RenderStyle and RenderStyleMode properties.
<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" />
Assign the icon’s CSS class to the IconCssClass property to add an icon to your button. The IconPosition property specifies the icon position.
<DxButton RenderStyle="ButtonRenderStyle.Dark"
Text="Undo" Title="Undo the last action."
IconCssClass="undo" />
<DxButton RenderStyle="ButtonRenderStyle.Dark"
Text="Redo"
Title="Restore the previously undone action."
IconCssClass="redo"
IconPosition="ButtonIconPosition.AfterText" />
.undo {
width: 16px;
height: 16px;
background-image: url("../images/undo.svg");
margin: 0 8px 0 0;
}
.redo {
width: 16px;
height: 16px;
background-image: url("../images/redo.svg");
margin: 0 0 0 8px;
}
To hide the button, set the Visible property to false.
Use the SizeMode property to specify a button size. The following code snippet 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 additional information, refer to Size Modes.
Handle the Click event to respond to the button’s click.
<DxButton ...
Click="@Handler">
@code {
// ...
void Handler(MouseEventArgs args) {
Console.WriteLine("I am clicked!");
}
}
If you use the NavigateUrl property together with the Click event’s handler, the browser handles the event first and then navigates to the specified URL.
To submit a form with a button click, 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" />
You can use the ChildContent property to add custom content to your button and customize its appearance and behavior:
<DxButton RenderStyle="ButtonRenderStyle.Info"
Click="@Like"
IconCssClass="btn-icon btn-icon-like"
SizeMode="Params.SizeMode"
Text="Like">
@context
<span class="ms-1">@likes</span>
</DxButton>
@* ... *@
@code {
int likes;
void Like(MouseEventArgs args) {
likes++;
}
protected override void OnInitialized() {
likes = 1;
}
}
.btn-icon-like {
-webkit-mask-repeat: no-repeat;
mask-repeat: no-repeat;
}
Run Demo: Button — Custom Content
If a Blazor application throws unexpected exceptions, refer to the following help topic: Troubleshooting.
Object ComponentBase DxComponentBase DxButtonBase DxButton
See Also