Articles in this section
Category / Section

How to expand or collapse Accordion programmatically in Xamarin.Forms (SfAccordion)

3 mins read

You can programmatically expand or collapse the AccordionItem in Xamarin.Forms SfAccordion by binding the model property to AccordionItem.IsExpanded property.



IsExpanded model property is bound to IsExpanded property of AccordionItem to expand or collapse when update property value programmatically.


    <syncfusion:AccordionItem IsExpanded="{Binding IsExpand}">
            <Grid HeightRequest="60">
                <Label Text="{Binding Name}" FontSize="Medium"/>
                        <RowDefinition Height="50"/>
                        <RowDefinition Height="50"/>
                    <Label Text="{Binding Description}"/>
                    <Button x:Name="btn" Grid.Row="1" Text="{Binding Name}" Command="{Binding Path=BindingContext.ButtonCommand, Source={x:Reference Accordion}}" CommandParameter="{x:Reference btn}"/>



OnExpandCollapse is used to change the IsExpand property to expand or collapse the item.


public class ItemInfoRepository
    public Command<object> ExpandCollapse{ get; set; }
    public ItemInfoRepository()
        ExpandCollapse= new Command<object>(OnExpandCollapse);
    private void OnExpandCollapse (object obj)
        var item = (obj as Button).BindingContext as ItemInfo;
        item.IsExpand = !item.IsExpand;


View sample in GitHub

Did you find this information helpful?
Help us improve this page
Please provide feedback or comments
Comments (0)
Please sign in to leave a comment