Articles in this section
Category / Section

How to retrieve the expanding Accordion item index in Xamarin.Forms (SfAccordion)?

1 min read

You can get the index of AccordionItem when expanding in Xamarin.Forms SfAccordion.

C#

You can get the index from the ExpandingAndCollapsingEventArgs of the Expanding event.

namespace AccordionXamarin.Behavior
{
    public class Behavior : Behavior<SfAccordion>
    {
        SfAccordion Accordion;
 
        protected override void OnAttachedTo(SfAccordion bindable)
        {
            Accordion = bindable;
            Accordion.Expanding += Accordion_Expanding;
            base.OnAttachedTo(bindable);
        }
 
        private void Accordion_Expanding(object sender, ExpandingAndCollapsingEventArgs e)
        {
            App.Current.MainPage.DisplayAlert("", "AccordionItem expanded at index " + e.Index, "Ok");
        }
    }
}

View sample in GitHub

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