How To Bind Command In .Net Maui Accordion

Sample date Updated on Apr 09, 2026
accordion accordion-item bind-command maui

This sample demonstrates how to bind a Command to items generated inside a Syncfusion SfAccordion in a .NET MAUI application.

For the official documentation and additional details about .NET MAUI DataGrid (SfDataGrid), please refer: Getting Started with .NET MAUI DataGrid

Overview

This repo shows a practical pattern for wiring commands from the page's view model to controls inside an item template that is generated by BindableLayout.ItemsSource on the SfAccordion control. The technique uses an x:Reference to the SfAccordion element and then binds the inner item's Command to a command exposed on the page's BindingContext (the page view-model). That lets each generated AccordionItem's inner controls (for example an ImageButton) call into the page-level command and pass the item as a CommandParameter.

Key points covered

  • Using BindableLayout.ItemsSource with SfAccordion to generate items from a collection.
  • Binding AccordionItem header and content to the item model.
  • Invoking a page-level ICommand from inside an item template using Source={x:Reference ...} and BindingContext.

XAML

Below is the exact XAML used in this sample to wire the command from the page's view-model into the generated item template. Note how the ImageButton binds Command to BindingContext.ShowDetailsCommand on the SfAccordion reference and passes the current item as the CommandParameter.

<ContentPage.BindingContext>
    <local:ItemInfoRepository x:Name="viewModel" />
</ContentPage.BindingContext>

<accordion:SfAccordion x:Name="accordion"
                        BindableLayout.ItemsSource="{Binding Info}"
                        ExpandMode="SingleOrNone">
    <BindableLayout.ItemTemplate>
        <DataTemplate>
            <accordion:AccordionItem>
                <accordion:AccordionItem.Header>
                    <Grid Padding="5,0,0,0"
                            HeightRequest="50">
                        <Label Text="{Binding Name}"
                                FontSize="20" />
                    </Grid>
                </accordion:AccordionItem.Header>
                <accordion:AccordionItem.Content>
                    <Grid BackgroundColor="#C0C0C0"
                            Padding="5,0,0,0">
                        <Grid.ColumnDefinitions>
                            <ColumnDefinition Width="*" />
                            <ColumnDefinition Width="65" />
                        </Grid.ColumnDefinitions>
                        <Label Text="{Binding Description}"
                                VerticalOptions="Center" />
                        <Grid Grid.Column="1"
                                Padding="10"
                                BackgroundColor="#C0C0C0">
                            <ImageButton BackgroundColor="{OnPlatform WinUI=#C0C0C0}"
                                            Source="details.png"
                                            Command="{Binding Path=BindingContext.ShowDetailsCommand, Source={x:Reference accordion}}"
                                            CommandParameter="{Binding .}" />
                        </Grid>
                    </Grid>
                </accordion:AccordionItem.Content>
            </accordion:AccordionItem>
        </DataTemplate>
    </BindableLayout.ItemTemplate>
</accordion:SfAccordion>

How it works

  • The ContentPage.BindingContext is set to an instance of ItemInfoRepository (the view-model). That view-model exposes an Info collection and a ShowDetailsCommand.
  • BindableLayout.ItemsSource creates one AccordionItem per element in the Info collection; each generated item's BindingContext is the item itself.
  • Inside the item template, the ImageButton cannot see the page-level command directly because its DataContext is the item. Using Source={x:Reference accordion} and then BindingContext.ShowDetailsCommand accesses the page's command and allows the item to pass itself as the parameter (CommandParameter={Binding .}).
Conclusion

I hope you enjoyed learning about how to bind a Command to items in .NET MAUI Accordion(SfAccordion).

You can refer to our .NET MAUI Accordion feature tour page to know about its other groundbreaking feature representations. You can also explore our .NET MAUI Accordion documentation to understand how to present and manipulate data.

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 forums, Direct-Trac, or feedback portal. We are always happy to assist you!

Up arrow