Class SfButton
Represents a graphical user interface Microsoft.AspNetCore.Components.ComponentBase that triggers events when clicked, supporting text, icons, SVG, or a combination as its content.
Inherited Members
Namespace: Syncfusion.Blazor.Buttons
Assembly: Syncfusion.Blazor.dll
Syntax
public class SfButton : SfBaseComponent
Remarks
Button content can be set using the Content property for simple strings or by embedding content within the SfButton tag. Both text and HTML elements (such as icons or SVG) are supported, allowing for a flexible UI experience.
Examples
The following code example demonstrates a basic button initialized with the Content property.
<SfButton Content="Click" />
Constructors
SfButton()
Declaration
public SfButton()
Properties
ChildContent
Gets or sets the child content for the SfButton control, including strings and HTML elements. If not specified, button content will be rendered using the Content property.
Declaration
public RenderFragment ChildContent { get; set; }
Property Value
Type | Description |
---|---|
Microsoft.AspNetCore.Components.RenderFragment | A Microsoft.AspNetCore.Components.RenderFragment representing the child content. The default value is |
Remarks
You can specify child content within the SfButton tag either as a string or an HTML element. The string content may also be specified by the Content property.
Examples
The following code example demonstrates specifying child content within the button tag:
<SfButton>
<span>HTML Content <i class="e-icons e-add"></i></span>
</SfButton>
Content
Gets or sets the string content to be displayed in the SfButton component.
Declaration
public string Content { get; set; }
Property Value
Type | Description |
---|---|
System.String | A |
Remarks
To use HTML structure within the button, specify it as child content using the ChildContent property.
Examples
The following code example shows how to specify button content via this property:
<SfButton Content="Submit" />
Created
Gets or sets an event callback that is invoked when the button rendering is completed.
Declaration
public EventCallback<object> Created { get; set; }
Property Value
Type | Description |
---|---|
Microsoft.AspNetCore.Components.EventCallback<System.Object> | An Microsoft.AspNetCore.Components.EventCallback<> that fires after component render. |
Remarks
You can use this event to perform custom logic or initialization when the button component is rendered in the DOM for the first time.
Examples
<SfButton Created="@OnReady" Content="Loaded!" />
@code {
private void OnReady(object args)
{
// Additional logic post render
}
}
CssClass
Gets or sets one or more CSS class names to customize the visual appearance of the button.
Declaration
public string CssClass { get; set; }
Property Value
Type | Description |
---|---|
System.String | A |
Remarks
Use this property to apply one or more custom styles to the button in addition to Syncfusion built-in classes.
Examples
This example demonstrates applying a style via the CssClass property:
<SfButton CssClass="e-primary e-custom-style" />
Disabled
Gets or sets a value that determines whether the button control is enabled or disabled.
Declaration
public bool Disabled { get; set; }
Property Value
Type | Description |
---|---|
System.Boolean |
|
Remarks
When this property is set to true
, all user interaction with the button is prevented.
Examples
<SfButton Content="Save" Disabled="true" />
EnableRtl
Gets or sets a value that determines whether the right-to-left (RTL) direction is enabled for the button.
Declaration
public bool EnableRtl { get; set; }
Property Value
Type | Description |
---|---|
System.Boolean |
|
Remarks
Enabling this property is beneficial for languages that are read from right to left.
Examples
<SfButton Content="عرض" EnableRtl="true" />
IconCss
Gets or sets the CSS class name(s) for including an icon or image in the button.
Declaration
public string IconCss { get; set; }
Property Value
Type | Description |
---|---|
System.String | A |
Remarks
When set, the button displays the specified icon or image alongside its content.
Examples
<SfButton IconCss="e-icons e-add" Content="Add Item" />
IconPosition
Gets or sets how the icon is positioned relative to button content.
Declaration
public IconPosition IconPosition { get; set; }
Property Value
Type | Description |
---|---|
IconPosition | A IconPosition enumeration value specifying the icon position. The default is Left. |
Remarks
Examples
<SfButton IconCss="e-icons e-edit" IconPosition="IconPosition.Right" Content="Edit" />
IsPrimary
Gets or sets a value indicating whether the button is styled as a primary action button.
Declaration
public virtual bool IsPrimary { get; set; }
Property Value
Type | Description |
---|---|
System.Boolean |
|
Remarks
Primary buttons highlight important actions in the UI using distinctive styling.
Examples
<SfButton IsPrimary="true" Content="Submit" />
IsToggle
Gets or sets a value indicating whether the button acts as a toggle button.
Declaration
public bool IsToggle { get; set; }
Property Value
Type | Description |
---|---|
System.Boolean |
|
Remarks
When enabled, each click toggles the button's active state.
Examples
<SfButton IsToggle="true" Content="Bold" />
OnClick
Gets or sets an event callback raised when the button is clicked through UI interaction.
Declaration
public EventCallback<MouseEventArgs> OnClick { get; set; }
Property Value
Type | Description |
---|---|
Microsoft.AspNetCore.Components.EventCallback<Microsoft.AspNetCore.Components.Web.MouseEventArgs> | An Microsoft.AspNetCore.Components.EventCallback<> representing the click event handler. |
Remarks
The OnClick event is triggered only for user-initiated clicks on the button. Programmatic invocations do not fire this event.
Examples
<SfButton OnClick="@Clicked" Content="Click Me" />
@code {
private void Clicked(MouseEventArgs args)
{
// Handle click event
}
}
Methods
BuildRenderTree(RenderTreeBuilder)
Declaration
protected override void BuildRenderTree(RenderTreeBuilder __builder)
Parameters
Type | Name | Description |
---|---|---|
Microsoft.AspNetCore.Components.Rendering.RenderTreeBuilder | __builder |
FocusAsync()
Asynchronously sets focus to the button, allowing programmatic keyboard or click interactions.
Declaration
public Task FocusAsync()
Returns
Type | Description |
---|---|
System.Threading.Tasks.Task | A System.Threading.Tasks.Task representing the asynchronous operation. |
Remarks
Use this method to programmatically set focus on the button element from code.
Examples
await buttonRef.FocusAsync();
OnAfterRenderAsync(Boolean)
Declaration
protected override Task OnAfterRenderAsync(bool firstRender)
Parameters
Type | Name | Description |
---|---|---|
System.Boolean | firstRender |
Returns
Type |
---|
System.Threading.Tasks.Task |
Overrides
OnParametersSetAsync()
Declaration
protected override Task OnParametersSetAsync()
Returns
Type |
---|
System.Threading.Tasks.Task |