Toolbar

in namespace DotVVM.BusinessPack.Controls

Renders a responsive Toolbar component.

Usage & Scenarios

Toolbar groups actions and input controls in a horizontal bar. Its ItemGroups collection determines which controls appear together.

Sample 1: Review a draft

ButtonItem approves the current title, ToggleButtonItem flags the draft, and DropDownListItem selects its section. The right-aligned DropDownButtonItem opens a PopupTemplate for renaming the draft. Other toolbar inputs include ComboBoxItem and ColorPickerItem.

In Business Pack 5.0.1 the built-in tb:ItemGroup.Items is a List<IToolbarItem>, which DotVVM 5 cannot populate from markup. In C# you can assign this list directly. Here, ToolbarGroup derives from ItemGroupBase and accepts a list of DotvvmControl so you can write the items and their bindings in DotHTML. Register the group once at startup.

<bp:Toolbar>
    <review:ToolbarGroup>
        <tb:ButtonItem Text="Approve" Click="{command: ApprovedTitle = Title}" />
        <tb:ToggleButtonItem Text="Priority" Checked="{value: Priority}" />
        <tb:DropDownListItem DataSource="{value: Sections}" SelectedValue="{value: Section}" AllowUnselect="false" />
    </review:ToolbarGroup>
    <review:ToolbarGroup AlignToRight="true">
        <tb:DropDownButtonItem Text="Rename draft">
            <PopupTemplate>
                <label>Draft title: <bp:TextBox Text="{value: Title}" /></label>
            </PopupTemplate>
        </tb:DropDownButtonItem>
    </review:ToolbarGroup>
</bp:Toolbar>

<p>{{value: Section}}: {{value: Title}} <strong Visible="{value: Priority}">(priority)</strong></p>
<p>Last approved: {{value: ApprovedTitle}}</p>
using DotVVM.Framework.ViewModel;

namespace DotvvmWeb.Views.Docs.Controls.businesspack.Toolbar.sample1
{
    public class ViewModel : DotvvmViewModelBase
    {
        public string Title { get; set; } = "Field notes";
        public string ApprovedTitle { get; set; } = "None";
        public string[] Sections { get; set; } = new[] { "News", "Opinion" };
        public string Section { get; set; } = "News";
        public bool Priority { get; set; }
    }
}
using System.Collections.Generic;
using DotVVM.BusinessPack.Controls.ToolbarItems;
using DotVVM.Framework.Binding;
using DotVVM.Framework.Controls;

namespace DotvvmWeb.Views.Docs.Controls.businesspack.Toolbar.sample1
{
    [ControlMarkupOptions(AllowContent = false, DefaultContentProperty = nameof(Items))]
    public class ToolbarGroup : ItemGroupBase
    {
        public ToolbarGroup(BindingCompilationService bindingService) : base(bindingService) { }

        [MarkupOptions(AllowBinding = false, MappingMode = MappingMode.InnerElement, Required = true)]
        public List<DotvvmControl> Items
        {
            get => (List<DotvvmControl>)GetValue(ItemsProperty);
            set => SetValue(ItemsProperty, value);
        }

        public static readonly DotvvmProperty ItemsProperty =
            DotvvmProperty.Register<List<DotvvmControl>, ToolbarGroup>(g => g.Items);

        protected override IEnumerable<DotvvmControl> GetToolbarControls() => Items;
    }
}
using DotVVM.Framework.Configuration;

namespace DotvvmWeb.Views.Docs.Controls.businesspack.Toolbar.sample1
{
    public class Startup : IDotvvmStartup
    {
        public void Configure(DotvvmConfiguration config, string applicationPath)
        {
            config.Markup.AddCodeControls("review", typeof(ToolbarGroup));
        }
    }
}

Properties

Name Type Description Notes Default Value
property icon ItemGroups List<ItemGroupBase> Gets or sets a collection of toolbar items organized in groups.
attribute
inner element
static value
bindable
default
null

HTML produced by the control