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.
Implements
Inherited Members
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
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#:
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#:
<toolkit:SfButton
x:Name="button"
Text="Button Text"
BackgroundImageSource="dotnet_bot.png"
BackgroundImageAspect="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#:
<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>
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#:
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#:
<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>
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 |
|
Examples
Below is an example of how to configure the IsCheckable property using XAML and C#:
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 |
|
Examples
Below is an example of how to configure the IsChecked property using XAML and C#:
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#:
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#:
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#:
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#:
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
ChangeVisualState()
Changes the visual state of the button based on its current properties
Declaration
protected override void ChangeVisualState()
Overrides
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
Finalize()
Destructor of the SfButton class
Declaration
protected override void Finalize()
Overrides
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
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
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 |