menu

MAUI Toolkit

  • User Guide
  • Demos
  • Support
Class SfButton - MAUI-ToolKit API Reference | Syncfusion

    Show / Hide Table of Contents

    Class SfButton

    The SfButton class provides a way for users to interact with the application by clicking or tapping. It can display text, an icon, or both, and supports various customization options.

    Inheritance
    System.Object
    SfView
    ButtonBase
    SfButton
    Implements
    IDrawableLayout
    Microsoft.Maui.Graphics.IDrawable
    Microsoft.Maui.IAbsoluteLayout
    Microsoft.Maui.ILayout
    Microsoft.Maui.IView
    Microsoft.Maui.IElement
    Microsoft.Maui.ITransform
    Microsoft.Maui.IContainer
    System.Collections.Generic.IList<Microsoft.Maui.IView>
    System.Collections.Generic.ICollection<Microsoft.Maui.IView>
    System.Collections.Generic.IEnumerable<Microsoft.Maui.IView>
    System.Collections.IEnumerable
    Microsoft.Maui.ISafeAreaView
    Microsoft.Maui.IPadding
    Microsoft.Maui.ICrossPlatformLayout
    Microsoft.Maui.IVisualTreeElement
    Inherited Members
    ButtonBase.BackgroundImageSource
    ButtonBase.BackgroundImageSourceProperty
    ButtonBase.Clicked
    ButtonBase.Command
    ButtonBase.CommandParameter
    ButtonBase.CommandParameterProperty
    ButtonBase.CommandProperty
    ButtonBase.EnableRippleEffect
    ButtonBase.EnableRippleEffectProperty
    ButtonBase.FontAttributes
    ButtonBase.FontAttributesProperty
    ButtonBase.FontAutoScalingEnabled
    ButtonBase.FontAutoScalingEnabledProperty
    ButtonBase.FontFamily
    ButtonBase.FontFamilyProperty
    ButtonBase.FontSize
    ButtonBase.FontSizeProperty
    ButtonBase.HorizontalTextAlignment
    ButtonBase.HorizontalTextAlignmentProperty
    ButtonBase.ImageAlignment
    ButtonBase.ImageAlignmentProperty
    ButtonBase.ImageSize
    ButtonBase.ImageSizeProperty
    ButtonBase.ImageSource
    ButtonBase.ImageSourceProperty
    ButtonBase.OnHandlerChanged()
    ButtonBase.Padding
    ButtonBase.PaddingProperty
    ButtonBase.ShowIcon
    ButtonBase.ShowIconProperty
    ButtonBase.Stroke
    ButtonBase.StrokeProperty
    ButtonBase.Text
    ButtonBase.TextProperty
    ButtonBase.VerticalTextAlignment
    ButtonBase.VerticalTextAlignmentProperty
    SfView.Children
    SfView.ClipToBounds
    Namespace: Syncfusion.Maui.Toolkit.Buttons
    Assembly: Syncfusion.Maui.Toolkit.dll
    Syntax
    public class SfButton : ButtonBase, IDrawableLayout, IDrawable, IAbsoluteLayout, ILayout, IView, IElement, ITransform, IContainer, IList<IView>, ICollection<IView>, IEnumerable<IView>, IEnumerable, ISafeAreaView, IPadding, ICrossPlatformLayout, IVisualTreeElement, ISemanticsProvider, ITouchListener, ITapGestureListener, IGestureListener, ITextElement, IParentThemeElement, IThemeElement
    Examples

    The below example shows how to initialize the SfButton

    • XAML
    • C#
    <toolkit:SfButton
          x:Name="button"
          Text="Button"
          HeightRequest="50"
          WidthRequest="200"/>
    SfButton button = new SfButton();
    button.Text = "Button";
    button.WidthRequest = 200;
    button.HeightRequest = 50;

    Constructors

    SfButton()

    Initializes a new instance of the SfButton class.

    Declaration
    public SfButton()

    Fields

    BackgroundImageAspectProperty

    Identifies the BackgroundImageAspect bindable property.

    Declaration
    public static readonly BindableProperty BackgroundImageAspectProperty
    Field Value
    Type Description
    Microsoft.Maui.Controls.BindableProperty

    The identifier for BackgroundImageAspect bindable property.

    BackgroundProperty

    Identifies the Background bindable property.

    Declaration
    public static readonly BindableProperty BackgroundProperty
    Field Value
    Type Description
    Microsoft.Maui.Controls.BindableProperty

    The identifier for Background bindable property.

    ContentProperty

    Identifies the Content bindable property.

    Declaration
    public static readonly BindableProperty ContentProperty
    Field Value
    Type Description
    Microsoft.Maui.Controls.BindableProperty

    The identifier for Content bindable property.

    CornerRadiusProperty

    Identifies the CornerRadius bindable property.

    Declaration
    public static readonly BindableProperty CornerRadiusProperty
    Field Value
    Type Description
    Microsoft.Maui.Controls.BindableProperty

    The identifier for CornerRadius bindable property.

    DashArrayProperty

    Identifies the DashArray bindable property.

    Declaration
    public static readonly BindableProperty DashArrayProperty
    Field Value
    Type Description
    Microsoft.Maui.Controls.BindableProperty

    The identifier for DashArray bindable property.

    IsCheckableProperty

    Identifies the IsCheckable bindable property.

    Declaration
    public static readonly BindableProperty IsCheckableProperty
    Field Value
    Type Description
    Microsoft.Maui.Controls.BindableProperty

    The identifier for IsCheckable bindable property.

    IsCheckedProperty

    Identifies the IsChecked bindable property.

    Declaration
    public static readonly BindableProperty IsCheckedProperty
    Field Value
    Type Description
    Microsoft.Maui.Controls.BindableProperty

    The identifier for IsChecked bindable property.

    LineBreakModeProperty

    Identifies the LineBreakMode bindable property.

    Declaration
    public static readonly BindableProperty LineBreakModeProperty
    Field Value
    Type Description
    Microsoft.Maui.Controls.BindableProperty

    The identifier for LineBreakMode bindable property.

    StrokeThicknessProperty

    Identifies the StrokeThickness bindable property.

    Declaration
    public static readonly BindableProperty StrokeThicknessProperty
    Field Value
    Type Description
    Microsoft.Maui.Controls.BindableProperty

    The identifier for StrokeThickness bindable property.

    TextColorProperty

    Identifies the TextColor bindable property.

    Declaration
    public static readonly BindableProperty TextColorProperty
    Field Value
    Type Description
    Microsoft.Maui.Controls.BindableProperty

    The identifier for TextColor bindable property.

    TextTransformProperty

    Identifies the TextTransform bindable property.

    Declaration
    public static readonly BindableProperty TextTransformProperty
    Field Value
    Type Description
    Microsoft.Maui.Controls.BindableProperty

    The identifier for TextTransform bindable property.

    Properties

    Background

    Gets or sets the value of background. This property can be used to give background color to the control.

    Declaration
    public Brush Background { get; set; }
    Property Value
    Type Description
    Microsoft.Maui.Controls.Brush

    The default value is SolidColorBrush(Color.FromArgb("#6750A4")) .

    Examples

    Below is an example of how to configure the Background property using XAML and C#:

    • XAML
    • C#
    <toolkit:SfButton
            x:Name="button"
            Text="Button Text"
            Background="Green"/>
    SfButton button = new SfButton();
    button.Text = "Button Text";
    button.Background = new SolidColorBrush(Colors.Green);

    BackgroundImageAspect

    Gets or sets the value of the background image aspect. This property can be used to set an aspect for background image of Button.

    Declaration
    public Aspect BackgroundImageAspect { get; set; }
    Property Value
    Type Description
    Microsoft.Maui.Aspect

    The default value is Aspect.AspectFill.

    Examples

    Below is an example of how to configure the BackgroundImageAspect property using XAML and C#:

    • XAML
    • C#
    <toolkit:SfButton
           x:Name="button"
           Text="Button Text"
           BackgroundImageSource="dotnet_bot.png"
           BackgroundImageAspect="Fill"/>
    SfButton button = new SfButton();
    button.Text = "Button Text";
    button.BackgroundImageSource = "dotnet_bot.png";
    button.BackgroundImageAspect = Aspect.Fill;

    Content

    Gets or sets the value of the content. This property can be used to set custom view to the button control.

    Declaration
    public DataTemplate Content { get; set; }
    Property Value
    Type Description
    Microsoft.Maui.Controls.DataTemplate

    The default value is null.

    Examples

    Below is an example of how to configure the Content property using XAML and C#:

    • XAML
    • C#
    <toolkit:SfButton Text = "Button Text"
           WidthRequest="120">
           <DataTemplate>
               <HorizontalStackLayout Spacing = "8" Padding="5">
                  <ActivityIndicator Color = "White" IsRunning="True"/>
                  <Label Text = "Loading..." VerticalOptions="Center"/>
               </HorizontalStackLayout>
           </DataTemplate>
    </toolkit:SfButton>
    var customContent = new DataTemplate(() =>
    {
        var activityIndicator = new ActivityIndicator
        {
            Color = Colors.White,
            IsRunning = true,
        };
        var label = new Label
        {
            Text = "Loading...",
            VerticalOptions = LayoutOptions.Center
        };
        var stackLayout = new HorizontalStackLayout
        {
            Spacing = 8,
            Padding = new Thickness(5)
        };
        stackLayout.Children.Add(activityIndicator);
        stackLayout.Children.Add(label);
        return stackLayout
    });
    SfButton button = new SfButton
    {
       Text = "Button Text",
       WidthRequest = 120,
       Content = customContent
    };
    Content = button;

    CornerRadius

    Gets or sets the value of corner radius. This property can be used to customize the corners of button control.

    Declaration
    public CornerRadius CornerRadius { get; set; }
    Property Value
    Type Description
    Microsoft.Maui.CornerRadius

    The default value is 20.

    Examples

    Below is an example of how to configure the CornerRadius property using XAML and C#:

    • XAML
    • C#
    <toolkit:SfButton
           x:Name="button"
           Text="Button Text"
           CornerRadius="10"/>
    SfButton button = new SfButton();
    button.Text = "Button Text";
    button.CornerRadius = 10;

    DashArray

    Gets or sets the value of dash array of the border. This property can be used to customize the dash of border.

    Declaration
    public float[] DashArray { get; set; }
    Property Value
    Type Description
    System.Single[]

    The default value is float[]{0,0}.

    Examples

    Below is an example of how to configure the DashArray property using XAML and C#:

    • XAML
    • C#
    <toolkit:SfButton
           x:Name="button"
           Text="Button Text"
           StrokeThickness="4">
           <buttons:SfButton.DashArray>
               <x:Array Type = "{x:Type x:Single}" >
                  < x:Single>2</x:Single>
                  <x:Single>2</x:Single>
               </x:Array>
           </buttons:SfButton.DashArray>
    </toolkit:SfButton>
    SfButton button = new SfButton();
    button.Text = "Button Text";
    button.StrokeThickness = 4;
    button.DashArray = new float[] { 2, 2 };

    IsCheckable

    Gets or sets a value indicating whether the control is in checkable state or not. This property can be used to change the state of the control.

    Declaration
    public bool IsCheckable { get; set; }
    Property Value
    Type Description
    System.Boolean

    true if checkable is enabled; otherwise, false.

    Examples

    Below is an example of how to configure the IsCheckable property using XAML and C#:

    • XAML
    • C#
    <toolkit:SfButton
           x:Name="button"
           Text="Button Text"
           IsCheckable ="True"/>
    SfButton button = new SfButton();
    button.Text = "Button Text";
    button.IsCheckable = true;

    IsChecked

    Gets or sets a value indicating whether the control is checkable. It is used to check the state of the control.

    Declaration
    public bool IsChecked { get; set; }
    Property Value
    Type Description
    System.Boolean

    true if checked is enabled; otherwise, false.

    Examples

    Below is an example of how to configure the IsChecked property using XAML and C#:

    • XAML
    • C#
    <toolkit:SfButton
           x:Name="button"
           Text="Button Text"
           IsCheckable ="True"
           IsChecked="True"/>
    SfButton button = new SfButton();
    button.Text = "Button Text";
    button.IsCheckable = true;
    button.IsChecked = true;

    LineBreakMode

    Gets or sets the value of line breakmode. This property can be used to customize the line breakmode of the text.

    Declaration
    public LineBreakMode LineBreakMode { get; set; }
    Property Value
    Type Description
    Microsoft.Maui.LineBreakMode

    The default value is NoWrap.

    Examples

    Below is an example of how to configure the LineBreakMode property using XAML and C#:

    • XAML
    • C#
    <toolkit:SfButton
           x:Name="button"
           Text="Button Text"
           LineBreakMode="TailTruncation"/>
    SfButton button = new SfButton();
    button.Text = "Button Text";
    button.LineBreakMode = LineBreakMode.TailTruncation;

    StrokeThickness

    Gets or sets the value of stroke thickness. This property can be used to give border thickness to button control.

    Declaration
    public double StrokeThickness { get; set; }
    Property Value
    Type Description
    System.Double

    The default value is 0d.

    Examples

    Below is an example of how to configure the StrokeThickness property using XAML and C#:

    • XAML
    • C#
    <toolkit:SfButton
           x:Name="button"
           Text="Button Text"
           StrokeThickness="4"/>
    SfButton button = new SfButton();
    button.Text = "Button Text";
    button.StrokeThickness = 4;

    TextColor

    Gets or sets the value of text color. This property can be used to give text color to the text in control.

    Declaration
    public Color TextColor { get; set; }
    Property Value
    Type Description
    Microsoft.Maui.Graphics.Color

    The default value is Colors.White.

    Examples

    Below is an example of how to configure the TextColor property using XAML and C#:

    • XAML
    • C#
    <toolkit:SfButton
           x:Name="button"
           Text="Button Text"
           TextColor="White"/>
    SfButton button = new SfButton();
    button.Text = "Button Text";
    button.TextColor = Colors.White;

    TextTransform

    Gets or sets the value of text transform. This property is used to specify the text transformation options for text processing.

    Declaration
    public TextTransform TextTransform { get; set; }
    Property Value
    Type Description
    Microsoft.Maui.TextTransform

    The default value is "Default", indicating that default transform is applied.

    Examples

    Below is an example of how to configure the TextTransform property using XAML and C#:

    • XAML
    • C#
    <toolkit:SfButton
           x:Name="button"
           Text="Button Text"
           TextTransform="Uppercase"/>
    SfButton button = new SfButton();
    button.Text = "Button Text";
    button.TextTransform = TextTransform.Uppercase;

    Methods

    ArrangeContent(Rect)

    Arrange content method.

    Declaration
    protected override Size ArrangeContent(Rect bounds)
    Parameters
    Type Name Description
    Microsoft.Maui.Graphics.Rect bounds
    Returns
    Type Description
    Microsoft.Maui.Graphics.Size

    the size.

    Overrides
    Syncfusion.Maui.Toolkit.SfView.ArrangeContent(Microsoft.Maui.Graphics.Rect)

    ChangeVisualState()

    Changes the visual state of the button based on its current properties

    Declaration
    protected override void ChangeVisualState()
    Overrides
    Syncfusion.Maui.Toolkit.ButtonBase.ChangeVisualState()

    DrawOutline(ICanvas, RectF)

    Draws an outline on the provided canvas for the current view.

    Declaration
    protected override void DrawOutline(ICanvas canvas, RectF dirtyRect)
    Parameters
    Type Name Description
    Microsoft.Maui.Graphics.ICanvas canvas

    The canvas on which the outline will be drawn.

    Microsoft.Maui.Graphics.RectF dirtyRect

    The area to be updated on the canvas (dirty rectangle).

    Overrides
    Syncfusion.Maui.Toolkit.ButtonBase.DrawOutline(Microsoft.Maui.Graphics.ICanvas, Microsoft.Maui.Graphics.RectF)

    Finalize()

    Destructor of the SfButton class

    Declaration
    protected override void Finalize()
    Overrides
    ButtonBase.Finalize()

    GetSemanticsNodesCore(Double, Double)

    Returns the semantics node list

    Declaration
    protected override List<SemanticsNode> GetSemanticsNodesCore(double width, double height)
    Parameters
    Type Name Description
    System.Double width
    System.Double height
    Returns
    Type
    System.Collections.Generic.List<Syncfusion.Maui.Toolkit.Graphics.Internals.SemanticsNode>
    Overrides
    Syncfusion.Maui.Toolkit.SfView.GetSemanticsNodesCore(System.Double, System.Double)

    MeasureContent(Double, Double)

    Measures the required size for the content based on given width and height constraints.

    Declaration
    protected override Size MeasureContent(double widthConstraint, double heightConstraint)
    Parameters
    Type Name Description
    System.Double widthConstraint
    System.Double heightConstraint
    Returns
    Type
    Microsoft.Maui.Graphics.Size
    Overrides
    Syncfusion.Maui.Toolkit.ButtonBase.MeasureContent(System.Double, System.Double)

    OnDraw(ICanvas, RectF)

    Drawing method of button control.

    Declaration
    protected override void OnDraw(ICanvas canvas, RectF dirtyRect)
    Parameters
    Type Name Description
    Microsoft.Maui.Graphics.ICanvas canvas

    The canvas.

    Microsoft.Maui.Graphics.RectF dirtyRect

    The rect

    Overrides
    Syncfusion.Maui.Toolkit.ButtonBase.OnDraw(Microsoft.Maui.Graphics.ICanvas, Microsoft.Maui.Graphics.RectF)

    Implements

    IDrawableLayout
    Microsoft.Maui.Graphics.IDrawable
    Microsoft.Maui.IAbsoluteLayout
    Microsoft.Maui.ILayout
    Microsoft.Maui.IView
    Microsoft.Maui.IElement
    Microsoft.Maui.ITransform
    Microsoft.Maui.IContainer
    System.Collections.Generic.IList<>
    System.Collections.Generic.ICollection<>
    System.Collections.Generic.IEnumerable<>
    System.Collections.IEnumerable
    Microsoft.Maui.ISafeAreaView
    Microsoft.Maui.IPadding
    Microsoft.Maui.ICrossPlatformLayout
    Microsoft.Maui.IVisualTreeElement
    Back to top Generated by DocFX
    Copyright © 2001 - 2025 Syncfusion Inc. All Rights Reserved