Class SfSwitch
Represents the SfSwitch class.
Implements
Inherited Members
Namespace: Syncfusion.Maui.Buttons
Assembly: Syncfusion.Maui.Buttons.dll
Syntax
public class SfSwitch : SfView, IDrawableLayout, IDrawable, IAbsoluteLayout, ILayout, IView, IElement, ITransform, IContainer, IList<IView>, ICollection<IView>, IEnumerable<IView>, IEnumerable, ISafeAreaView, IPadding, ICrossPlatformLayout, IVisualTreeElement, ISemanticsProvider, IKeyboardListener, ITouchListener, ITapGestureListener, IGestureListener, IParentThemeElement, IThemeElement
Examples
The below example shows how to initialize the switch.
Constructors
SfSwitch()
Initializes a new instance of the SfSwitch class.
Declaration
public SfSwitch()
Fields
AllowIndeterminateStateProperty
Identifies the AllowIndeterminateState bindable property.
Declaration
public static readonly BindableProperty AllowIndeterminateStateProperty
Field Value
Type | Description |
---|---|
Microsoft.Maui.Controls.BindableProperty | The identifier for the AllowIndeterminateState bindable property. |
IsEnabledProperty
Identifies the IsEnabled bindable property.
Declaration
public static readonly BindableProperty IsEnabledProperty
Field Value
Type | Description |
---|---|
Microsoft.Maui.Controls.BindableProperty | The identifier for the IsEnabled bindable property. |
IsOnProperty
Identifies the IsOn bindable property.
Declaration
public static readonly BindableProperty IsOnProperty
Field Value
Type | Description |
---|---|
Microsoft.Maui.Controls.BindableProperty | The identifier for the IsOn bindable property. |
SwitchSettingsProperty
Identifies the SwitchSettings bindable property.This property contains all the properties of SfSwitch control.
Declaration
public static readonly BindableProperty SwitchSettingsProperty
Field Value
Type | Description |
---|---|
Microsoft.Maui.Controls.BindableProperty | The identifier for the SwitchSettings bindable property. |
Properties
AllowIndeterminateState
Gets or sets a value indicating whether to allow indeterminate state or not. When sfSwitch AllowIndeterminateState as false, it moves IsOn to true when it is null.
Declaration
public bool AllowIndeterminateState { get; set; }
Property Value
Type |
---|
System.Boolean |
Examples
The below example shows how to AllowIndeterminateState value in switch.
IsEnabled
Gets or sets a value indicating whether users can interact with the control.
Declaration
public bool IsEnabled { get; set; }
Property Value
Type |
---|
System.Boolean |
Examples
The below example shows how to set IsEnabled value in switch.
IsOn
Gets or set a value indicating whether the switch is in the "On" or "Off" state.
Declaration
public Nullable<bool> IsOn { get; set; }
Property Value
Type |
---|
System.Nullable<System.Boolean> |
Remarks
If the AllowIndeterminateState is true, the switch state will be null.
Examples
The below example shows how to set IsOn value in switch.
SwitchSettings
Gets or Sets the value of SwitchSettings.
Declaration
public SwitchSettings SwitchSettings { get; set; }
Property Value
Type |
---|
SwitchSettings |
Examples
The below example shows how to set SwitchSettings values in switch
<syncfusion:SfSwitch>
<VisualStateManager.VisualStateGroups>
<VisualStateGroup x:Name="CommonStates">
<VisualState x:Name="On">
<VisualState.Setters>
<Setter Property="SwitchSettings">
<Setter.Value>
<syncfusion:SwitchSettings
ThumbStrokeThickness="2"
TrackStrokeThickness="2"
TrackHeightRequest="30"
TrackWidthRequest="50"
TrackCornerRadius="22"
ThumbCornerRadius="20"
ThumbHeightRequest="22"
ThumbWidthRequest="22"
ThumbBackground="#FFFFFF"
TrackBackground="#6750A4"
ThumbStroke="#FFFFFF"
TrackStroke="#6750A4"
IconColor="#21005E"
CustomPath = "M14.2051 0.744141L15.207 1.74609L5.69727 11.2559L0.792969 6.35156L1.79492 5.34961L5.69727 9.25195L14.2051 0.744141Z" />
</Setter.Value>
</Setter>
</VisualState.Setters>
</VisualState>
<VisualState x:Name="Off">
<VisualState.Setters>
<Setter Property="SwitchSettings">
<Setter.Value>
<syncfusion:SwitchSettings
ThumbStrokeThickness="2"
TrackStrokeThickness="2"
TrackHeightRequest="30"
TrackWidthRequest="50"
TrackCornerRadius="20"
ThumbCornerRadius="20"
ThumbHeightRequest="14"
ThumbWidthRequest="14"
ThumbBackground="#79747E"
TrackBackground="#22029BFF"
TrackStroke="#79747E"
ThumbStroke="#79747E"/>
</Setter.Value>
</Setter>
</VisualState.Setters>
</VisualState>
</VisualStateGroup>
</VisualStateManager.VisualStateGroups>
</syncfusion:SfSwitch>
Methods
ChangeVisualState()
Declaration
protected override void ChangeVisualState()
Finalize()
Disconnect constructor
Declaration
protected override void 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.Graphics.Internals.SemanticsNode> |
Overrides
MeasureContent(Double, Double)
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
OnBindingContextChanged()
Call when the binding context is changed.
Declaration
protected override void OnBindingContextChanged()
Overrides
OnDraw(ICanvas, RectF)
Declaration
protected override void OnDraw(ICanvas canvas, RectF dirtyRect)
Parameters
Type | Name | Description |
---|---|---|
Microsoft.Maui.Graphics.ICanvas | canvas | |
Microsoft.Maui.Graphics.RectF | dirtyRect |
Overrides
OnHandlerChanged()
Declaration
protected override void OnHandlerChanged()
Overrides
OnSizeAllocated(Double, Double)
Declaration
protected override void OnSizeAllocated(double width, double height)
Parameters
Type | Name | Description |
---|---|---|
System.Double | width | |
System.Double | height |
Events
StateChanged
Invoke the event when the state of SfSwitch is changed.
Declaration
public event EventHandler<SwitchStateChangedEventArgs> StateChanged
Event Type
Type |
---|
System.EventHandler<SwitchStateChangedEventArgs> |
StateChanging
Occurs when the state of the control is about to change.
Declaration
public event EventHandler<SwitchStateChangingEventArgs> StateChanging
Event Type
Type |
---|
System.EventHandler<SwitchStateChangingEventArgs> |
Remarks
The StateChanging event is raised when the state of the control is about to change. It provides an opportunity to perform additional actions or validation before the state changes.