RibbonBar
RibbonBar is an Office-style command bar. It organizes an application's commands into tabs across the top of a page or window and replaces the traditional menu bar and toolbars. Commands are arranged in a three-level hierarchy:
- pages, shown as tabs;
- groups, the titled panels inside a page;
- items, the commands inside a group: buttons, split buttons, check boxes, radio buttons, text boxes, combo boxes, separators, or any Wisej.NET control.
Every item's events are also raised on the RibbonBar itself, so a whole ribbon can be handled in a single event handler.

Installation
Add the Wisej-4-RibbonBar package to your Wisej.NET project:
dotnet add package Wisej-4-RibbonBar
The package targets .NET Framework 4.8 and .NET 8 or later (including the -windows, Android, iOS and Mac Catalyst targets). After a rebuild, RibbonBar shows up in the Visual Studio toolbox. A new RibbonBar docks to the top (DockStyle.Top) and sizes its height to its content (AutoSize = true).
Structure
| Level | Type | Collection | Notes |
|---|---|---|---|
| Application button | RibbonBarAppButton | RibbonBar.AppButton | An optional tab before the first page. Hidden until you set Visible = true. |
| Page | RibbonBarPage | RibbonBar.Pages | One tab. |
| Group | RibbonBarGroup | RibbonBarPage.Groups | A titled panel of items, with an optional button next to the title. |
| Item | RibbonBarItem subclasses | RibbonBarGroup.Items | Laid out in columns, see Columns and orientation. |
All three collections can be indexed by position or by Name, e.g. ribbonBar1.Pages["home"].Groups["clipboard"].Items["paste"].
Getting started
This example builds a Home page with a Clipboard group: one large Paste button and two small buttons stacked beside it. A single ItemClick handler on the RibbonBar handles all three.
- C#
- VB.NET
using Wisej.Web.Ext.RibbonBar;
var ribbonBar = new RibbonBar();
var home = new RibbonBarPage { Name = "home", Text = "&Home" };
var clipboard = new RibbonBarGroup { Name = "clipboard", Text = "Clipboard" };
clipboard.Items.Add(new RibbonBarItemButton { Name = "paste", Text = "Paste", ImageSource = "icon-paste" });
clipboard.Items.Add(new RibbonBarItemButton { Name = "cut", Text = "Cut", Orientation = Orientation.Horizontal });
clipboard.Items.Add(new RibbonBarItemButton { Name = "copy", Text = "Copy", Orientation = Orientation.Horizontal });
home.Groups.Add(clipboard);
ribbonBar.Pages.Add(home);
ribbonBar.ItemClick += (s, e) =>
{
switch (e.Item.Name)
{
case "paste": Paste(); break;
case "cut": Cut(); break;
case "copy": Copy(); break;
}
};
this.Controls.Add(ribbonBar);
Imports Wisej.Web.Ext.RibbonBar
Dim ribbonBar As New RibbonBar()
Dim home As New RibbonBarPage With {.Name = "home", .Text = "&Home"}
Dim clipboard As New RibbonBarGroup With {.Name = "clipboard", .Text = "Clipboard"}
clipboard.Items.Add(New RibbonBarItemButton With {.Name = "paste", .Text = "Paste", .ImageSource = "icon-paste"})
clipboard.Items.Add(New RibbonBarItemButton With {.Name = "cut", .Text = "Cut", .Orientation = Orientation.Horizontal})
clipboard.Items.Add(New RibbonBarItemButton With {.Name = "copy", .Text = "Copy", .Orientation = Orientation.Horizontal})
home.Groups.Add(clipboard)
ribbonBar.Pages.Add(home)
AddHandler ribbonBar.ItemClick,
Sub(s, e)
Select Case e.Item.Name
Case "paste" : Paste()
Case "cut" : Cut()
Case "copy" : Copy()
End Select
End Sub
Me.Controls.Add(ribbonBar)
The & in "&Home" makes H the page's mnemonic key. Set UseMnemonic to false to show the ampersand as text instead.
The RibbonBar is fully editable in the designer. Click any page, group or item on the design surface to select it and edit its properties in the Properties window. Use the collection editors of Pages, Groups and Items to add, remove and reorder elements.
Items
| Item | What it is | Specific members |
|---|---|---|
RibbonBarItemButton | A push button, optionally with a drop-down menu. | Orientation, Pushed, MenuItems; events PushedChanged, ItemClicked |
RibbonBarItemSplitButton | A button with a separate arrow that opens its MenuItems. | Everything RibbonBarItemButton has |
RibbonBarItemButtonGroup | A horizontal row of buttons treated as one item. | Buttons |
RibbonBarItemCheckBox | A check box. | Checked, CheckedChanged |
RibbonBarItemRadioButton | A radio button. | Checked, CheckedChanged |
RibbonBarItemTextBox | A label followed by a text field. | Value, FieldWidth (120), ValueChanged |
RibbonBarItemComboBox | A label followed by a drop-down list. | Items (string[]), Value, Editable (false), FieldWidth (120), ValueChanged |
RibbonBarItemSeparator | A vertical line between items. | — |
RibbonBarItemControl | Hosts any Wisej.NET Control. | Control, Orientation |
All items share the members of RibbonBarItem: Text, ToolTipText, Enabled, Visible, Tag, ColumnBreak, the Click event, and the image properties Image, ImageSource, ImageIndex and ImageKey. ImageSource takes a URL, a relative path or a theme icon name. ImageIndex and ImageKey pick an image from the RibbonBar's ImageList.
The RibbonBar's theme mixin ships a set of ready-made icons you can use in ImageSource: ribbon-paste, ribbon-copy, ribbon-cut, ribbon-save, ribbon-save-as, ribbon-save-all, ribbon-print, ribbon-open, ribbon-folder, ribbon-add-file, ribbon-add-folder, ribbon-delete, ribbon-settings, ribbon-about and more.
Buttons with menus
Any RibbonBarItemButton can carry a drop-down menu in MenuItems, a collection of standard Wisej.NET MenuItem objects. On a plain button the whole button opens the menu. On a RibbonBarItemSplitButton, the button fires Click and only the arrow opens the menu.
- C#
- VB.NET
var paste = new RibbonBarItemSplitButton { Name = "paste", Text = "Paste", ImageSource = "ribbon-paste" };
paste.MenuItems.Add(new MenuItem("Keep source formatting") { Name = "pasteSource" });
paste.MenuItems.Add(new MenuItem("Keep text only") { Name = "pasteText" });
// The button itself...
paste.Click += (s, e) => Paste();
// ...and a menu item, handled on the RibbonBar.
this.ribbonBar1.MenuButtonItemClick += (s, e) =>
{
AlertBox.Show($"{e.Item.Name}: {e.MenuItem.Name}");
};
Dim paste As New RibbonBarItemSplitButton With {.Name = "paste", .Text = "Paste", .ImageSource = "ribbon-paste"}
paste.MenuItems.Add(New MenuItem("Keep source formatting") With {.Name = "pasteSource"})
paste.MenuItems.Add(New MenuItem("Keep text only") With {.Name = "pasteText"})
' The button itself...
AddHandler paste.Click, Sub(s, e) Paste()
' ...and a menu item, handled on the RibbonBar.
AddHandler Me.RibbonBar1.MenuButtonItemClick,
Sub(s, e) AlertBox.Show($"{e.Item.Name}: {e.MenuItem.Name}")
A menu click fires ItemClicked on the button and MenuButtonItemClick on the RibbonBar. Both take a RibbonBarMenuItemEventArgs, whose Item is the button and MenuItem the menu entry.
Toggle buttons
Set Pushed to show a button in its pressed state, for commands that switch something on and off, like Bold. The button doesn't toggle itself: set Pushed in the Click handler. Each change fires PushedChanged.
private void buttonBold_Click(object sender, EventArgs e)
{
this.buttonBold.Pushed = !this.buttonBold.Pushed;
}
Button groups
A RibbonBarItemButtonGroup lays out its Buttons side by side, like the alignment buttons in a word processor. It takes regular buttons and split buttons.
Hosting other controls
When the built-in items aren't enough, RibbonBarItemControl hosts any Wisej.NET control, such as a date picker, a numeric editor or a color picker, inside a group.
- C#
- VB.NET
var dateItem = new RibbonBarItemControl { Text = "Due date" };
this.ribbonBarGroupSchedule.Items.Add(dateItem);
// Assign the control after the item is in a group that belongs to a RibbonBar.
dateItem.Control = new DateTimePicker { Format = DateTimePickerFormat.Short, Width = 120 };
Dim dateItem As New RibbonBarItemControl With {.Text = "Due date"}
Me.RibbonBarGroupSchedule.Items.Add(dateItem)
' Assign the control after the item is in a group that belongs to a RibbonBar.
dateItem.Control = New DateTimePicker With {.Format = DateTimePickerFormat.Short, .Width = 120}
Assign Control after adding the item to a group that is already part of a RibbonBar. The hosted control is moved into the RibbonBar, and if the item isn't attached yet, the control ends up with no parent. The control's AutoSize is set to false and its size follows the item. Disposing the item disposes the hosted control too.
Columns and orientation
A group stacks its items vertically in columns. A new column starts after any item whose ColumnBreak is true. Large buttons (Orientation.Vertical, the default: icon above the text), vertical hosted controls and separators always take a column of their own. Small buttons (Orientation.Horizontal: icon beside the text), check boxes, radio buttons, text boxes and combo boxes stack in the current column.
- C#
- VB.NET
var font = new RibbonBarGroup { Text = "Font" };
font.Items.Add(new RibbonBarItemButton { Text = "Bold", Orientation = Orientation.Horizontal });
font.Items.Add(new RibbonBarItemButton { Text = "Italic", Orientation = Orientation.Horizontal });
font.Items.Add(new RibbonBarItemButton { Text = "Underline", Orientation = Orientation.Horizontal, ColumnBreak = true });
font.Items.Add(new RibbonBarItemCheckBox { Text = "Superscript" });
font.Items.Add(new RibbonBarItemCheckBox { Text = "Subscript" });
Dim font As New RibbonBarGroup With {.Text = "Font"}
font.Items.Add(New RibbonBarItemButton With {.Text = "Bold", .Orientation = Orientation.Horizontal})
font.Items.Add(New RibbonBarItemButton With {.Text = "Italic", .Orientation = Orientation.Horizontal})
font.Items.Add(New RibbonBarItemButton With {.Text = "Underline", .Orientation = Orientation.Horizontal, .ColumnBreak = True})
font.Items.Add(New RibbonBarItemCheckBox With {.Text = "Superscript"})
font.Items.Add(New RibbonBarItemCheckBox With {.Text = "Subscript"})
This gives two columns: Bold, Italic and Underline in the first, the two check boxes in the second.
Groups
A RibbonBarGroup shows its Text as a title under its items. Set ShowButton to true to add the small corner button next to the title, the one visible in the New group at the top of this page. It usually opens a dialog with more options. A click fires the group's Click event and GroupClick on the RibbonBar.
this.ribbonBarGroupFont.ShowButton = true;
this.ribbonBarGroupFont.Click += (s, e) => new FontOptionsDialog().ShowDialog();
Setting Enabled = false on a group, or on a page, disables all the items inside it at once.
Pages and selection
SelectedPage returns or sets the active page. Until a page is selected, it returns the first visible page. Changing it, from code or when the user clicks a tab, fires SelectedPageChanged. Setting RibbonBarPage.Selected to true does the same from the page's side.
Hiding a page and showing it on demand is how you build contextual tabs, such as Picture Tools that only appear while a picture is selected:
- C#
- VB.NET
private void pictureBox1_Click(object sender, EventArgs e)
{
var page = this.ribbonBar1.Pages["pictureTools"];
page.Visible = true;
this.ribbonBar1.SelectedPage = page;
}
private void ribbonBar1_SelectedPageChanged(object sender, EventArgs e)
{
this.labelStatus.Text = "Page: " + this.ribbonBar1.SelectedPage?.Text;
}
Private Sub PictureBox1_Click(sender As Object, e As EventArgs) Handles PictureBox1.Click
Dim page = Me.RibbonBar1.Pages("pictureTools")
page.Visible = True
Me.RibbonBar1.SelectedPage = page
End Sub
Private Sub RibbonBar1_SelectedPageChanged(sender As Object, e As EventArgs) Handles RibbonBar1.SelectedPageChanged
Me.LabelStatus.Text = "Page: " & Me.RibbonBar1.SelectedPage?.Text
End Sub
Use TabBackColor and TabForeColor to make a contextual tab stand out, like the green Edit tab in the screenshot at the top of this page.
SelectedPage only accepts a page from this RibbonBar's Pages collection, and it can't be set to null. Either mistake throws an exception.
Application button
The AppButton is the colored tab before the first page (File in the screenshot at the top). It isn't a page: clicking it fires AppButtonClick, which is where you open a backstage view, a side panel or a menu. It's hidden by default.
- C#
- VB.NET
this.ribbonBar1.AppButton.Visible = true;
this.ribbonBar1.AppButton.Text = "File";
this.ribbonBar1.AppButton.BackColor = Color.FromArgb(0x2B, 0x57, 0x9A);
this.ribbonBar1.AppButton.ForeColor = Color.White;
this.ribbonBar1.AppButtonClick += (s, e) => this.fileMenuPanel.Visible = true;
Me.RibbonBar1.AppButton.Visible = True
Me.RibbonBar1.AppButton.Text = "File"
Me.RibbonBar1.AppButton.BackColor = Color.FromArgb(&H2B, &H57, &H9A)
Me.RibbonBar1.AppButton.ForeColor = Color.White
AddHandler Me.RibbonBar1.AppButtonClick, Sub(s, e) Me.FileMenuPanel.Visible = True
Compact view
With CompactView set to true, only the tab strip is visible and no page is shown as selected, which frees up vertical space. When the user clicks a tab, its page opens temporarily over the content below the ribbon, and it closes again at the next click outside the ribbon. Clicks inside the ribbon's own drop-down menus and popups don't close it. On the server, SelectedPage keeps the last page the user chose. Each switch fires CompactViewChanged.
private void buttonCollapse_Click(object sender, EventArgs e)
{
this.ribbonBar1.CompactView = !this.ribbonBar1.CompactView;
}
Tools
Tools is a standard ComponentToolCollection. Its tools appear at the right end of the tab strip, like the help and settings icons in the screenshot at the top. A click fires ToolClick. See Embedded Tools in the user guide.
Validation
CausesValidation is false by default. With the default, clicking a ribbon command doesn't validate the control that currently has focus. Set it to true when commands such as Save must first run the active editor's Validating handler. See Validation.
Events
| Event | Raised on | When |
|---|---|---|
ItemClick | RibbonBar | Any item is clicked. e.Item is the item. |
ItemValueChanged | RibbonBar | The user changes an item's value: a check box, radio button, text box or combo box. |
MenuButtonItemClick | RibbonBar | A drop-down menu item of a button or split button is clicked. |
GroupClick | RibbonBar | A group's title button is clicked. |
SelectedPageChanged | RibbonBar | The active page changes. |
AppButtonClick | RibbonBar | The application button is clicked. |
CompactViewChanged | RibbonBar | CompactView changes. |
ToolClick | RibbonBar | A tool in Tools is clicked. |
Click | Each item and group | The same click, raised on the element itself. |
CheckedChanged / ValueChanged / PushedChanged | The specific item type | The item's value changes. |
Styling
RibbonBar.mixin.theme is embedded in the extension and loaded automatically. It defines the ribbonbar, ribbonbar-group and ribbonbar-item appearances, the icon set listed above, and five colors you can override in a mixin of your own:
| Color | Default | Used for |
|---|---|---|
ribbonBar | #f5f6f7 | Ribbon background |
ribbonPage | #f5f6f7 | Page background |
ribbonBarText | #3F3F3F | Tab text |
ribbonGroupText | #5F5F5F | Group titles |
ribbonItemText | #2B2B2B | Item text |
{
"name": "MyApp.mixin",
"colors": {
"ribbonBar": "#FFFFFF",
"ribbonPage": "#FFFFFF",
"ribbonGroupText": "#6B7280"
}
}
See Theming and editing a mixin in the Theme Builder.