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 show or hide AccordionItem in Xamarin.Forms (SfAccordion)

Platform: Xamarin.Forms |
Control: SfAccordion

You can show or hide the AccoridonItem in Xamarin.Forms SfAccordion by handling the ViewModel bound collection with add or remove action.

C#

OnHideOrShow handler is used to show or hide the particular AccordionItem by updating the collection.

public class BehaviorClass : Behavior<ContentPage>
{
    Contact deletedItem = null;
    SfAccordion accordion;
    Button HideOrShow;
    protected override void OnAttachedTo(ContentPage bindable)
    {
        base.OnAttachedTo(bindable);
        accordion = bindable.FindByName<SfAccordion>("Accordion");
        HideOrShow = bindable.FindByName<Button>("HideOrShow");
        HideOrShow.Clicked += OnHideOrShow;
    }
    private void OnHideOrShow(object sender, EventArgs e)
    {
        var items = (sender as Button).BindingContext as ViewModel;
 
        if (deletedItem == null)
        {
            deletedItem = items.ContactsInfo[2];
            items.ContactsInfo.RemoveAt(2);
        }
        else
        {
            items.ContactsInfo.Insert(2, deletedItem);
            deletedItem = null;
        }
    }
}

Output

A screenshot of a cell phone

Description automatically generated

View sample in GitHub

2X faster development

The ultimate Xamarin UI toolkit to boost your development speed.
ADD COMMENT
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