menu

Xamarin.Forms

  • Code Examples
  • Upgrade Guide
  • User Guide
  • Demos
  • Support
  • Forums
  • Download
Class SfExpander - Xamarin.Forms API Reference | Syncfusion

    Show / Hide Table of Contents

    Class SfExpander

    A class which is a container that provides a way to host a customizable header and content part as compound view. The content part gets expanded upon tapping the header part of the SfExpander.

    Inheritance
    System.Object
    SfExpander
    Implements
    System.IDisposable
    Namespace: Syncfusion.XForms.Expander
    Assembly: Syncfusion.Expander.XForms.dll
    Syntax
    public class SfExpander : View, IDisposable, IParentThemeElement, IThemeElement
    Remarks

    The SfExpander contains header and content which is fully customizable. The header of SfExpander includes indicator icon that can be used to expand and collapse the content and able to customize it. Expand and collapse of the view is controlled by IsExpanded property.

    Constructors

    SfExpander()

    Initializes a new instance of the SfExpander class.

    Declaration
    public SfExpander()

    Fields

    AnimationDurationProperty

    Identifies the AnimationDuration bindable property.

    Declaration
    public static readonly BindableProperty AnimationDurationProperty
    Field Value
    Type
    Xamarin.Forms.BindableProperty

    AnimationEasingProperty

    Identifies the AnimationEasing bindable property.

    Declaration
    public static readonly BindableProperty AnimationEasingProperty
    Field Value
    Type
    Xamarin.Forms.BindableProperty

    ContentProperty

    Identifies the Content bindable property.

    Declaration
    public static readonly BindableProperty ContentProperty
    Field Value
    Type
    Xamarin.Forms.BindableProperty
    Remarks

    This bindable property is read-only.

    DynamicSizeModeProperty

    Identifies the DynamicSizeMode bindable property.

    Declaration
    public static readonly BindableProperty DynamicSizeModeProperty
    Field Value
    Type
    Xamarin.Forms.BindableProperty

    HeaderBackgroundColorProperty

    Identifies the HeaderBackgroundColor bindable property.

    Declaration
    public static readonly BindableProperty HeaderBackgroundColorProperty
    Field Value
    Type
    Xamarin.Forms.BindableProperty

    HeaderIconPositionProperty

    Identifies the HeaderIconPosition bindable property.

    Declaration
    public static readonly BindableProperty HeaderIconPositionProperty
    Field Value
    Type
    Xamarin.Forms.BindableProperty
    Remarks

    This bindable property is read-only.

    HeaderProperty

    Identifies the Header bindable property.

    Declaration
    public static readonly BindableProperty HeaderProperty
    Field Value
    Type
    Xamarin.Forms.BindableProperty
    Remarks

    This bindable property is read-only.

    IconColorProperty

    Identifies the IconColor bindable property.

    Declaration
    public static readonly BindableProperty IconColorProperty
    Field Value
    Type
    Xamarin.Forms.BindableProperty

    IsExpandedProperty

    Identifies the IsExpanded bindable property.

    Declaration
    public static readonly BindableProperty IsExpandedProperty
    Field Value
    Type
    Xamarin.Forms.BindableProperty
    Remarks

    This bindable property is read-only.

    Properties

    AnimationDuration

    Gets or sets the value indicates how long the animation cycle should take when expand and collapse the SfExpander.

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

    The value indicates how long the animation cycle should take when expand and collapse the SfExpander.

    Remarks

    By default, the animation duration is 200d.

    Examples
    expander.AnimationDuration = 100d;

    AnimationEasing

    Gets or sets the AnimationEasing that specifies the rate of change of parameter over time or animation style of the expander.

    Declaration
    public AnimationEasing AnimationEasing { get; set; }
    Property Value
    Type Description
    AnimationEasing

    The type of animation that specifies the rate of change of parameter over time or animation style of the expander.

    Remarks

    Set this property as None to disable the animation for SfExpander.

    Examples
    expander.AnimationEasing = AnimationEasing.Linear;

    Content

    Gets or sets any kind of customizable visual element that can be loaded as content part of the SfExpander. The default value is null which displays an empty space when expanded.

    Declaration
    public View Content { get; set; }
    Property Value
    Type Description
    Xamarin.Forms.View

    The view to be loaded as the expander part of the SfExpander.

    Examples
    var content = new Label();
    content.Text = "SfExpander provides a way to add the content in an expandable area.";
    expander.Content = content;

    DynamicSizeMode

    Gets or sets the value indicating whether to update expander based on dynamic size changes of Header view and Content view.

    Declaration
    public DynamicSizeMode DynamicSizeMode { get; set; }
    Property Value
    Type
    DynamicSizeMode
    Examples
    expander.DynamicSizeMode = DynamicSizeMode.Content | DynamicSizeMode.Header;

    Header

    Gets or sets the view to be loaded as the header of the SfExpander. The header also contains the header view icon which is positioned based on the HeaderIconPosition property.

    Declaration
    public View Header { get; set; }
    Property Value
    Type Description
    Xamarin.Forms.View

    The view to be loaded as the header of the SfExpander.

    Remarks

    The view to be loaded as the header of the SfExpander. Customize the header part of the control with any desired view or layout. The header contains the header icon view that is positioned based on the HeaderIconPosition property. Customize the header icon position with start, end and none values which is configured using IconPosition enum.

    Examples
    var header = new Label();
    header.Text = DateTime.Now.ToString("hh:mm tt");
    expander.Header = header;

    HeaderBackgroundColor

    Gets or sets the background color for the expander header item.

    Declaration
    public Color HeaderBackgroundColor { get; set; }
    Property Value
    Type
    Xamarin.Forms.Color
    Examples
    expander.HeaderBackgroundColor = Color.Grey;

    HeaderIconPosition

    Gets or sets the IconPosition indicates that where to show the header view icon in the Header.

    Declaration
    public IconPosition HeaderIconPosition { get; set; }
    Property Value
    Type Description
    IconPosition

    The position indicates that where to show the header view icon in the Header.

    Examples
    expander.HeaderIconPosition = IconPosition.End;

    IconColor

    Gets or sets the expander icon color.

    Declaration
    public Color IconColor { get; set; }
    Property Value
    Type
    Xamarin.Forms.Color
    Examples
    expander.IconColor = Color.Grey;

    IsExpanded

    Gets or sets a value indicating whether the SfExpander is in Expanded state or Collapsed state.

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

    The boolean value indicating whether the SfExpander is in Expanded state or Collapsed state.

    Examples
    expander.IsExpanded = true;

    Methods

    ChangeVisualState()

    Helps to trigger the VisualState initially when View is loaded.

    Declaration
    protected override void ChangeVisualState()

    Dispose()

    Perform final clean up before it is released from memory.

    Declaration
    public void Dispose()

    Dispose(Boolean)

    Releases the unmanaged resources used by the component and optionally releases the managed resources.

    Declaration
    protected virtual void Dispose(bool disposing)
    Parameters
    Type Name Description
    System.Boolean disposing

    if true - release both managed and unmanaged resources; if false - release only unmanaged resources.

    OnBindingContextChanged()

    Notifies the change in BindingContext for the expander.

    Declaration
    protected override void OnBindingContextChanged()

    OnSizeAllocated(Double, Double)

    Allocates the size of item elements.

    Declaration
    protected override void OnSizeAllocated(double width, double height)
    Parameters
    Type Name Description
    System.Double width

    The new width of the element.

    System.Double height

    The new height of the element.

    RaiseCollapsedEvent()

    Raises the Collapsed event with ExpandedAndCollapsedEventArgs.

    Declaration
    protected void RaiseCollapsedEvent()

    RaiseCollapsingEvent()

    Raises the Collapsing event with ExpandingAndCollapsingEventArgs.

    Declaration
    protected bool RaiseCollapsingEvent()
    Returns
    Type Description
    System.Boolean

    Returns true if collapsing event is not triggered else inverse of ExpandingAndCollapsingEventArgs.Cancel value.

    See Also
    System.ComponentModel.CancelEventArgs

    RaiseExpandedEvent()

    Raises the Expanded event with ExpandedAndCollapsedEventArgs.

    Declaration
    protected void RaiseExpandedEvent()

    RaiseExpandingEvent()

    Raises the Expanding event with ExpandingAndCollapsingEventArgs.

    Declaration
    protected bool RaiseExpandingEvent()
    Returns
    Type Description
    System.Boolean

    Returns true if expanding event is not triggered else inverse of ExpandingAndCollapsingEventArgs.Cancel value.

    See Also
    System.ComponentModel.CancelEventArgs

    Events

    Collapsed

    This event occurs after an SfExpander is collapsed when tapping on the Header.

    Declaration
    public event EventHandler<ExpandedAndCollapsedEventArgs> Collapsed
    Event Type
    Type
    System.EventHandler<ExpandedAndCollapsedEventArgs>
    Remarks

    The event handler receives an argument of type ExpandingAndCollapsingEventArgs containing data related to this event.

    Examples
    expander.Collapsed += Expander_Collapsed;
    
    private void Expander_Collapsed(object sender, ExpandedAndCollapsedEventArgs e)
    {
        label.Text = "Burger and Pizza";
        expander.Header.BackgroundColor = Color.Aqua;
    }

    Collapsing

    This event occurs while an SfExpander is collapsing when tapping on the Header. It is possible to cancel the collapsing action using the System.ComponentModel.CancelEventArgs.Cancel property in the event args.

    Declaration
    public event EventHandler<ExpandingAndCollapsingEventArgs> Collapsing
    Event Type
    Type
    System.EventHandler<ExpandingAndCollapsingEventArgs>
    Remarks

    The user can control the expanding of content by using ExpandingAndCollapsingEventArgs of this event. If the Cancel property is set to true in the event's handler, the execution of the current event is cancelled.

    Examples
    expander.Collapsing += Expander_Collapsing;
    
    private void Expander_Collapsing(object sender, ExpandingAndCollapsingEventArgs e)
    {
        // Below code cancels the collapsing operation of the SfExpander control.
        e.Cancel = true;
    }

    Expanded

    This event occurs after an SfExpander is expanded when tapping on the Header.

    Declaration
    public event EventHandler<ExpandedAndCollapsedEventArgs> Expanded
    Event Type
    Type
    System.EventHandler<ExpandedAndCollapsedEventArgs>
    Remarks

    The event handler receives an argument of type ExpandingAndCollapsingEventArgs containing data related to this event.

    Examples
    expander.Expanded += Expander_Expanded;
    
    private void Expander_Expanded(object sender, ExpandedAndCollapsedEventArgs e)
    {
        label.Text = "Burger";
        expander.Header.BackgroundColor = Color.YellowGreen;
    }

    Expanding

    This event occurs while an SfExpander is expanding when tapping on the Header. It is possible to cancel the expanding action using the System.ComponentModel.CancelEventArgs.Cancel property in the event args.

    Declaration
    public event EventHandler<ExpandingAndCollapsingEventArgs> Expanding
    Event Type
    Type
    System.EventHandler<ExpandingAndCollapsingEventArgs>
    Remarks

    The user can control the expanding of content by using ExpandingAndCollapsingEventArgs of this event. If the Cancel property is set to true in the event's handler, the execution of the current event is cancelled.

    Examples
    expander.Expanding += Expander_Expanding;
    
    private void Expander_Expanding(object sender, ExpandingAndCollapsingEventArgs e)
    {
        // Below code cancels the expanding operation of the SfExpander control.
        e.Cancel = true;
    }

    Implements

    System.IDisposable
    Back to top Generated by DocFX
    Copyright © 2001 - 2025 Syncfusion Inc. All Rights Reserved