We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

How to bind command in Xamarin.Forms Accordion (SfAccordion)

Platform: Xamarin.Forms |
Control: SfAccordion

You can bind the ViewModel commands to content of AccordionItem in Xamarin.Forms SfAccordion.


ViewModel command to show the Accordion details.

namespace AccordionXamarin
    public class ItemInfoRepository
        public Command<object> ShowDetailsCommand { get; set; }
        public ItemInfoRepository()
            ShowDetailsCommand = new Command<object>(OnShowDetailClicked);
        private void OnShowDetailClicked(object obj)
            var item = obj as ItemInfo;
            App.Current.MainPage.DisplayAlert(item.Name, item.Description, "Ok");


Binding the ViewModel command to the ImageButton that is loaded inside the content of AccordionItem.

<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
        <local:ItemInfoRepository x:Name="viewModel"/>
    <accordion:SfAccordion x:Name="accordion" BindableLayout.ItemsSource="{Binding Info}" ExpandMode="SingleOrNone">
                        <Grid Padding="5,0,0,0" HeightRequest="50">
                            <Label Text="{Binding Name}" FontSize="20" />
                        <Grid BackgroundColor="LightGray" Padding="5,0,0,0">
                                <ColumnDefinition Width="*" />
                                <ColumnDefinition Width="45" />
                            <Label Text="{Binding Description}" VerticalOptions="Center"/>
                            <Grid Grid.Column="1" Padding="10" BackgroundColor="LightGray">
                                <ImageButton HeightRequest="30" WidthRequest="30" Source="Details.png" Command="{Binding Path=BindingContext.ShowDetailsCommand, Source={x:Reference accordion}}" CommandParameter="{Binding .}"/>

View sample in GitHub

2X faster development

The ultimate Xamarin UI toolkit to boost your development speed.
You must log in to leave a comment

Please sign in to access our KB

This page will automatically be redirected to the sign-in page in 10 seconds.

Up arrow icon

Warning Icon You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.Close Icon

Live Chat Icon For mobile