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
DataSource Object Gets or sets the source collection or a GridViewDataSet that contains data in the control.
attribute
inner element
static value
bindable
default
ExpandedItemIndex Int32 Gets or sets the index of the item which is currently expanded.
attribute
inner element
static value
bindable
default
-1
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
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
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
ItemsContent List<ICardItem> Gets or sets the content for accordion items bound from DataSource.
attribute
inner element
static value
bindable
default
ItemsFooterTemplate ITemplate Gets or sets the footer template for accordion items bound from DataSource.
attribute
inner element
static value
bindable
default
ItemsHeaderTemplate ITemplate Gets or sets the content for accordion items bound from DataSource.
attribute
inner element
static value
bindable
default
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
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
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.1/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 list item text.
<bs:Accordion ExpandedItemIndex="{value: Index}" 
              DataSource="{value: Panels}" 
              TextBinding="{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.

Send message