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 | |
|---|---|---|---|---|---|
| ClientIDMode | ClientIDMode | Gets or sets the client ID generation algorithm. |
attribute
static value
|
Static | |
| DataContext | Object | Gets or sets a data context for the control and its children. All value and command bindings are evaluated in context of this value. The DataContext is null in client-side templates. |
attribute
bindable
|
null | |
| ID | String | Gets or sets the control client ID within its naming container. |
attribute
static value
bindable
|
null | |
| IncludeInPage | Boolean | Gets or sets whether the control is included in the DOM of the page. |
attribute
static value
bindable
|
True | |
| InnerText | String | Gets or sets the inner text of the HTML element. Note that this property can only be used on HtmlGenericControl directly and when the control does not have any children. |
attribute
static value
bindable
|
null | |
| ItemGroups | List<ItemGroupBase> | Gets or sets a collection of toolbar items organized in groups. |
inner element
static value
default
|
null | |
| Visible | Boolean | Gets or sets whether the control is visible. When set to false, `style="display: none"` will be added to this control. |
attribute
static value
bindable
|
True |