Version: 2.0 |

DropDownButton

in namespace DotVVM.Framework.Controls.Bootstrap4

Renders a Bootstrap dropdown button.

Properties

Name Type Description Notes Default Value
AllowPopupFlip Boolean Gets or sets whether the popup can flip to a different direction when it does not fit on the page.
attribute
inner element
static value
bindable
default
True
ButtonContentTemplate ITemplate Gets or sets the template for the button content.
attribute
inner element
static value
bindable
default
ButtonType DropDownButtonType Gets or sets the type of the button.
attribute
inner element
static value
bindable
default
Button
ClickBinding ICommandBinding Gets or sets a binding which defines a click action for button items.
attribute
inner element
static value
bindable
default
DataSource Object Gets or sets the source collection or a GridViewDataSet that contains data in the control.
attribute
inner element
static value
bindable
default
DropDirection DropDirection Gets or sets the popup direction.
attribute
inner element
static value
bindable
default
DropDown
IsCollapsed Boolean Gets or sets whether the button is collapsed or not.
attribute
inner element
static value
bindable
default
True
IsEnabledBinding IValueBinding Gets or sets a value binding that points to a property indicating whether the item is disabled or not.
attribute
inner element
static value
bindable
default
IsSelectedBinding IValueBinding Gets or sets a value binding that points to a property indicating whether the item is selected or not.
attribute
inner element
static value
bindable
default
Items List<IDropDownButtonItem> Gets or sets a collection of items that is used when no DataSource is set.
attribute
inner element
static value
bindable
default
ItemsContentTemplate ITemplate Gets or sets the template for contents of the generated items when using the DataSource property.
attribute
inner element
static value
bindable
default
MenuAlignment DropdownMenuAlignment Gets or sets whether the popup will be aligned to the right of the button.
attribute
inner element
static value
bindable
default
Default
NavigateUrlBinding IValueBinding Gets or sets the value binding that points to a property which will be navigated to when the item is clicked.
attribute
inner element
static value
bindable
default
Size Size Gets or sets the size of the button.
attribute
inner element
static value
bindable
default
Default
Text String Gets or sets the button text.
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
Type BootstrapButtonColor Gets or sets the color of the button.
attribute
inner element
static value
bindable
default
Primary
VisualStyle ButtonVisualStyle Gets or sets whether the button has solid fill, or whether it is only an outline.
attribute
inner element
static value
bindable
default
SolidFill

Events

Name Type Description

Usage & Scenarios

Renders a button with a drop-down menu with the data-binding support.

https://getbootstrap.com/docs/4.1/components/dropdowns/

HTML Rendered by the Control

Sample 1: Basic Usage

The Text property specified the text on the button. Alternatively, you can use the ButtonTemplate property.

The Type property can specify whether the menu drops up or down.

The IsCollapsed property indicates whether the menu is open or not. You can also use it in data-binding.

Place <bs:DropDownButtonItem> controls inside the <bs:DropDownButton> control and use their NavigateUrl property to specify the link URL. You can place them inside the <Items> element, however it is not required because the Items is the default property of DropDownButton.

Because the class DropDownButtonItem inherits from the ListItem, please refer to the ListItem documentation for more information.

<bs:DropDownButton Text="Very Simple Dropdown">
  <Items>
    <bs:DropDownButtonItem NavigateUrl="https://www.google.com/">
      Google
    </bs:DropDownButtonItem>
    <bs:DropDownButtonItem NavigateUrl="https://github.com/riganti/dotvvm" Text="DotVVM" />
  </Items>
</bs:DropDownButton>

<bs:DropDownButton Text="Drop up Button" DropDownType="DropUp">
  <bs:DropDownButtonItem NavigateUrl="https://www.google.com/">
    <ButtonTemplate>
      Google is a <strong>search engine</strong>
    </ButtonTemplate>
  </bs:DropDownButtonItem>
  <bs:DropDownButtonItem NavigateUrl="https://github.com/riganti/dotvvm">
    DotVVM
  </bs:DropDownButtonItem>
</bs:DropDownButton>

<p>IsCollapsed: {{value: Collapsed}}</p>
<bs:DropDownButton IsCollapsed="{value: Collapsed}" Text="Collapse test">
  <bs:DropDownButtonItem NavigateUrl="https://www.google.com">Google</bs:DropDownButtonItem>
</bs:DropDownButton>
using DotVVM.Framework.ViewModel;

namespace DotvvmWeb.Views.Docs.Controls.bootstrap.DropDownButton.sample1
{
    public class ViewModel : DotvvmViewModelBase
    {
        public bool Collapsed { get; set; }
    }
}

Sample 2: Advanced Dropdown

The DropDownButtonItem control has the IsDisabled property which you can use to disable the menu item.

You can separate dropdown menu items using the bs:DropDownButtonSeparator control. You can also use the the bs:DropDownButtonHeader to specify a non-clickable title for a group of buttons.

The ButtonType property is used to apply Bootstrap styles to DropDownButton. If you need to place a custom content on the button and not just text, use the ButtonTemplate.

<bs:DropDownButton Text="Very Simple Dropdown with Headers" ButtonType="Success" >
  <bs:DropDownButtonHeader>Item 1</bs:DropDownButtonHeader>
  <bs:DropDownButtonItem NavigateUrl="https://www.google.com/">
    Google
  </bs:DropDownButtonItem>
  <bs:DropDownButtonHeader>Item 2</bs:DropDownButtonHeader>
  <bs:DropDownButtonItem NavigateUrl="https://github.com/riganti/dotvvm">
    DotVVM
  </bs:DropDownButtonItem>
</bs:DropDownButton>

<bs:DropDownButton>
  <ButtonTemplate>
    Very <strong>Simple Dropdown</strong> with separator and disabled value
  </ButtonTemplate>

  <bs:DropDownButtonItem NavigateUrl="https://www.google.com/" IsDisabled="true">
    Google
  </bs:DropDownButtonItem>
  <bs:DropDownButtonSeparator/>
  <bs:DropDownButtonItem NavigateUrl="https://github.com/riganti/dotvvm">
    DotVVM
  </bs:DropDownButtonItem>
</bs:DropDownButton>

Sample 3: DropDownButton Data-binding

You can also load the dropdown button items from a collection in the viewmodel using the DataSource property.

You have to specify the TextBinding which points to an appropriate property of the collection item. The URL of the item is specified using the NavigateUrlBinding property.

You can also use the IsDisabledBinding and IsSelectedBinding to specify which properties of the collection item declare the selected or disabled state of the button. The same logic applies to the ClickBinding property - use it if you want the buttons to invoke a command on the viewmodel.

<bs:DropDownButton Text="Dropdown Created From Data Source!"
                   DataSource="{value: LinksDataSet}"
                   IsDisabledBinding="{value: IsDisabled}"
                   IsSelectedBinding="{value: IsSelected}"
                   TextBinding="{value: Text}"
                   NavigateUrlBinding="{value: NavigateUrl}">
</bs:DropDownButton>
using System.Collections.Generic;
using System.Linq;
using DotVVM.Framework.ViewModel;

namespace DotvvmWeb.Views.Docs.Controls.bootstrap.DropDownButton.sample3
{
    public class ViewModel : DotvvmViewModelBase
    {
        public List<LinkItem> LinksDataSet { get; set; }

        private static IQueryable<LinkItem> GetData()
        {
            return new[]
            {
                new LinkItem() {  IsDisabled = false, IsSelected = false, NavigateUrl = "https://www.google.com/", Text = "Google"},
                new LinkItem() {  IsDisabled = false, IsSelected = false, NavigateUrl = "http://www.w3schools.com/html/", Text = "W3Schools"},
                new LinkItem() {  IsDisabled = false, IsSelected = true, NavigateUrl = "https://www.microsoft.com/en-us/", Text = "Microsoft"},
                new LinkItem() {  IsDisabled = false, IsSelected = false, NavigateUrl = "https://github.com/riganti/dotvvm", Text = "DotVVM Github"}
            }.AsQueryable();
        }

        public ViewModel()
        {
            LinksDataSet = new List<LinkItem>();
            foreach (LinkItem l in GetData())
            {
                LinksDataSet.Add(l);
            }
        }


    }
    public class LinkItem
    {
        public string Text { get; set; }
        public string NavigateUrl { get; set; }
        public bool IsSelected { get; set; }
        public bool IsDisabled { get; set; }

    }
}

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