Articles in this section
Category / Section

How to customize the appearance of Accordion in Xamarin.Forms (SfAccordion)?

1 min read

You can customize the appearance of Xamarin.Forms Accordion using VisualStateManager.

XAML

Defining the VisualStates to customize Accordion appearance.

<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
             xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
             xmlns:syncfusion="clr-namespace:Syncfusion.XForms.Accordion;assembly=Syncfusion.Expander.XForms"
             x:Class="AccordionXamarin.MainPage" Padding="{OnPlatform iOS='0,40,0,0'}">
 
    <ContentPage.Content>
        <syncfusion:SfAccordion x:Name="Accordion" ExpandMode="SingleOrNone" BindableLayout.ItemsSource="{Binding Info}">
            <BindableLayout.ItemTemplate>
                <DataTemplate>
                    <syncfusion:AccordionItem x:Name="AccordionItem">
                        <syncfusion:AccordionItem.Header>
                            <Grid HeightRequest="50" Padding="10,0">
                                <Label Text="{Binding Name}" VerticalOptions="Center" HorizontalOptions="StartAndExpand"/>
                            </Grid>
                        </syncfusion:AccordionItem.Header>
                        <syncfusion:AccordionItem.Content>
                            <Grid BackgroundColor="NavajoWhite" Padding="10">
                                <Label Text="{Binding Description}"/>
                            </Grid>
                        </syncfusion:AccordionItem.Content>
                        <VisualStateManager.VisualStateGroups>
                            <VisualStateGroupList>
                                <VisualStateGroup>
                                    <VisualState Name="Expanded">
                                        <VisualState.Setters>
                                            <Setter Property="HeaderBackgroundColor" Value="LightPink"/>
                                            <Setter Property="IconColor" Value="Red"/>
                                        </VisualState.Setters>
                                    </VisualState>
                                    <VisualState Name="Collapsed">
                                        <VisualState.Setters>
                                            <Setter Property="HeaderBackgroundColor" Value="LightGreen"/>
                                            <Setter Property="IconColor" Value="Blue"/>
                                        </VisualState.Setters>
                                    </VisualState>
                                </VisualStateGroup>
                            </VisualStateGroupList>
                        </VisualStateManager.VisualStateGroups>
                    </syncfusion:AccordionItem>
                </DataTemplate>
            </BindableLayout.ItemTemplate>
        </syncfusion:SfAccordion>
    </ContentPage.Content>
</ContentPage>

Output

Using VisualStateManager in Accordion

View sample in GitHub


Conclusion

I hope you enjoyed learning about how to customize the appearance of Accordion in Xamarin.Forms (SfAccordion).

You can refer to our Xamarin.Forms Accordion feature tour page to know about its other groundbreaking feature representations and documentation, and how to quickly get started for configuration specifications.

For current customers, you can check out our components from the License and Downloads page. If you are new to Syncfusion, you can try our 30-day free trial to check out our other controls.

If you have any queries or require clarifications, please let us know in the comments section below. You can also contact us through our support forumsDirect-Trac, or feedback portal. We are always happy to assist you!

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