Articles in this section
Category / Section

How to Show or Hide Accordion Item in .NET MAUI?

2 mins read

You can manage the visibility of an AccordionItem in MAUI Accordion by dynamically adding or removing items from the ViewModel bound collection.

This example demonstrates how to hide or show an accordion item using a button click event.

public class BehaviorExt: Behavior<ContentPage>
{
    Contact? deletedItem = null;
    SfAccordion? accordion;
    Button? button;
    protected override void OnAttachedTo(ContentPage bindable)
    {
        base.OnAttachedTo(bindable);
        accordion = bindable.FindByName<SfAccordion>("Accordion");
        button= bindable.FindByName<Button>("HideOrShow");
        button.Clicked += OnHideOrShow;
    }
    private void OnHideOrShow(object? sender, EventArgs e)
    {
        var items = (sender as Button)!.BindingContext as ContactViewModel;

        if (deletedItem == null)
        {
            deletedItem = items!.ContactsInfo![2];
            items.ContactsInfo.RemoveAt(2);
        }
        else
        {
            items!.ContactsInfo!.Insert(2, deletedItem);
            deletedItem = null;
        }
    }
}

Output

how_to_show_or_hide_accordion_item.gif

Download the complete sample on GitHub

Conclusion
I hope you enjoyed learning how to show or hide Accordion Items dynamically in .NET MAUI.
You can refer to our .NET MAUI Accordion feature tour page to know about its other groundbreaking feature representations and documentation, and how to quickly get started with configuration specifications. Explore our .NET MAUI Accordion example to understand how to create and manipulate data.
For current customers, you can check out our components from the License and Downloads page. If you are new to Syncfusion®, try our 30-day free trial to check out our other controls.
Please let us know in the comments section if you have any queries or require clarification. You can also contact us through our support forums, Direct-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