Version:
2.0

Accordion

in namespace DotVVM.Framework.Controls.Bootstrap4

Wraps a group of AccordionItem controls to create an accordion-like behavior.

Properties

Name Type Description Notes Default Value
property icon DataSource Object Gets or sets the source collection or a GridViewDataSet that contains data in the control.
attribute
inner element
static value
bindable
default
property icon ExpandedItemIndex Int32 Gets or sets the index of the item which is currently expanded.
attribute
inner element
static value
bindable
default
-1
property icon FooterTextBinding IValueBinding Gets or sets the value binding that points to a property which will be used as the footer text of the item.
attribute
inner element
static value
bindable
default
property icon HeaderTextBinding IValueBinding Gets or sets the value binding that points to a property which will be used as the header text of the item.
attribute
inner element
static value
bindable
default
property icon Items List<IAccordionItem> Gets or sets a collection of items that is used when no DataSource is set.
attribute
inner element
static value
bindable
default
property icon ItemsContent List<ICardItem> Gets or sets the content for accordion items bound from DataSource.
attribute
inner element
static value
bindable
default
property icon ItemsFooterTemplate ITemplate Gets or sets the footer template for accordion items bound from DataSource.
attribute
inner element
static value
bindable
default
property icon ItemsHeaderTemplate ITemplate Gets or sets the content for accordion items bound from DataSource.
attribute
inner element
static value
bindable
default
property icon SubtitleTextBinding IValueBinding Gets or sets the value binding that points to a property which will be used as the subtitle text of the item.
attribute
inner element
static value
bindable
default
property icon TextBinding IValueBinding Gets or sets the value binding that points to a property which will be used as the text of the item.
attribute
inner element
static value
bindable
default
property icon TitleTextBinding IValueBinding Gets or sets the value binding that points to a property which will be used as the title text of the item.
attribute
inner element
static value
bindable
default

Events

Name Type Description

Usage & Scenarios

Wraps a group of AccordionItem controls to create an accordion-like behavior. When you expand one of the items inside, the others will collapse. Only one item can be expanded at the same time.

https://getbootstrap.com/docs/4.3/components/collapse/#accordion-example

HTML Rendered by the Control

Sample 1: Basic Accordion

To use this control, just place several AccordionItem controls inside the Accordion control. The AccordionItem inherits from Card and can specify the IsExpanded property to indicate whether the item is expanded or not.

In the most common scenario, you need the first panel to be expanded while the others are collapsed.

<bs:Accordion>
  
  <bs:AccordionItem HeaderText="Card 1"
                    TitleText="Card 1"
                    Text="This is first accordion item." 
                    IsExpanded="true" />

  <bs:AccordionItem HeaderText="Card 2"
                    TitleText="Card 3"
                    Text="This is second accordion item." />

  <bs:AccordionItem HeaderText="Card 3"
                    TitleText="Card 3"
                    Text="This is third accordion item." />
  
</bs:Accordion>

Sample 2: Data-binding the Accordion

The ExpandedItemIndex property specifies the index of the accordion item which is selected.

The DataSource property can be used to generate the items from an IEnumerable in the viewmodel.

Then you can use the following properties which tell the control what property of the collection item will be used:

  • TextBinding specifies the property of the collection elements to be used as the content of the accordion item.
  • HeaderTextBinding specifies the text in the accordion item header.
  • FooterTextBinding specifies the text in the accordion item footer.
<bs:Accordion ExpandedItemIndex="{value: Index}" 
              DataSource="{value: Panels}" 
              TextBinding="{value: Text}" 
              HeaderTextBinding="{value: Text}" />

<p>Expanded panel index: {{value: Index}}</p>
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace DotvvmWeb.Views.Docs.Controls.bootstrap.Accordion.sample2
{
    public class ViewModel
    {
        public int Index { get; set; } = 1;

        public PanelData[] Panels { get; set; } =
        {
            new PanelData("Text 1"),
            new PanelData("Text 2"),
            new PanelData("Text 3")
        };
    }

    public class PanelData
    {
        public string Text { get; set; }

        public PanelData()
        {
        }

        public PanelData(string text)
        {
            Text = text;
        }
    }
}

Suggestions

Help & Contribute

The documentation is maintained on GitHub.
We'll be happy if you edit the page and create a pull request.

Edit on Github

Send message