HypernovaDesktop Components · docs
Binarymission
WPF › Ribbon › BinaryRibbonBarPanel

BinaryRibbonBarPanel

class.NET 6 / 8 / 10.NET Framework 4.8Binarymission.WPF.Controls.Office

The ribbon: a row of tabs, each holding labelled groups of commands, under the window's title, an application button and a quick access toolbar – the command surface of an Office-style application.

public partial class BinaryRibbonBarPanel : Control

Inherits from / implements: Control

Remarks

Put it at the top of a BinaryRibbonWindow, which draws the caption buttons and frame around it, as the main menu and toolbar of a document or line-of-business application.

Building a ribbon

Its content is Tabs: each BinaryRibbonTabItem holds BinaryRibbonGroups, and each group holds commands – BinaryRibbonButton, BinaryRibbonSplitButtonControl, BinaryRibbonDropDownButton, BinaryRibbonComboBox, BinaryRibbonGallery and the rest. Add ApplicationMenu, QuickAccessToolBar and TitleText.

Fitting the width

As the window narrows, the groups give way a step at a time from the last: their commands shrink – a large picture over the caption, then a small picture beside it, then the picture alone, as each command allows – and at last the group folds into one button that drops its commands down. SetMinSize, SetMaxSize and SetResizableSize set a command's steps. Below 240 logical pixels the tabs and commands are hidden (IsMinimized).

Showing more or less

DisplayState shows tabs and commands, tabs only (a clicked tab drops its commands over the document) or neither; Ctrl+F1, a double-click on a tab and the right-click menu switch it. RibbonLayout picks the classic three-row or the simplified one-line ribbon, and ContextualTabSet adds tabs for what is selected – a table, a picture – under a coloured title.

Keyboard, tips and skins

BinaryKeyTip.SetAccessKey gives a command a key tip, shown level by level on Alt or F10 in a BinaryRibbonWindow; BinaryRibbonScreenTipService.SetScreenTip gives it a titled screen tip. Users add commands to the quick access toolbar by right-clicking them, and GetQuickAccessToolBarState keeps their choice for the next run. Colours come from BinaryRibbonBuiltInSkinController.Skin.

Examples

An invoicing window with an application menu, a quick access toolbar and key tips; its code-behind class derives from BinaryRibbonWindow.

<bm:BinaryRibbonWindow x:Class="Invoicing.MainWindow"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:bm="clr-namespace:Binarymission.WPF.Controls.Office;assembly=Binarymission.WPF.Controls.BinaryRibbon"
    Title="Invoicing" Width="1100" Height="700">
  <DockPanel>
    <bm:BinaryRibbonBarPanel DockPanel.Dock="Top" TitleText="Invoicing - Northwind Traders">
      <bm:BinaryRibbonBarPanel.ApplicationMenu>
        <bm:BinaryRibbonApplicationMenu bm:BinaryKeyTip.AccessKey="F">
          <bm:BinaryRibbonApplicationMenuItem Header="New invoice" Image="Images/NewInvoice32.png" Click="OnNewInvoice" />
          <bm:BinaryRibbonApplicationMenuItem Header="Open..." Image="Images/Open32.png" Click="OnOpen" />
          <Separator />
          <bm:BinaryRibbonApplicationMenuItem Header="Exit" Click="OnExit" />
        </bm:BinaryRibbonApplicationMenu>
      </bm:BinaryRibbonBarPanel.ApplicationMenu>
      <bm:BinaryRibbonBarPanel.QuickAccessToolBar>
        <bm:BinaryRibbonQuickAccessToolBar>
          <bm:BinaryRibbonButton SmallImage="Images/Save16.png" ToolTip="Save" Click="OnSave" />
          <bm:BinaryRibbonButton SmallImage="Images/Undo16.png" ToolTip="Undo" Command="ApplicationCommands.Undo" />
        </bm:BinaryRibbonQuickAccessToolBar>
      </bm:BinaryRibbonBarPanel.QuickAccessToolBar>
      <bm:BinaryRibbonTabItem HeaderText="Home" bm:BinaryKeyTip.AccessKey="H">
        <bm:BinaryRibbonGroup TitleText="Invoice" CanShowModalDialog="True" ExecuteModalDialogLauncher="OnInvoiceOptions">
          <bm:BinaryRibbonButton Content="New" LargeImage="Images/NewInvoice32.png" bm:BinaryKeyTip.AccessKey="N" Click="OnNewInvoice" />
          <bm:BinaryRibbonButton Content="Send" LargeImage="Images/Send32.png" bm:BinaryKeyTip.AccessKey="S" Click="OnSendInvoice" />
        </bm:BinaryRibbonGroup>
        <bm:BinaryRibbonGroup TitleText="Clipboard">
          <bm:BinaryRibbonButton Content="Paste" LargeImage="Images/Paste32.png" Command="ApplicationCommands.Paste" />
          <bm:BinaryRibbonButton Content="Cut" SmallImage="Images/Cut16.png" bm:BinaryRibbonBarPanel.MaxSize="Medium" Command="ApplicationCommands.Cut" />
          <bm:BinaryRibbonButton Content="Copy" SmallImage="Images/Copy16.png" bm:BinaryRibbonBarPanel.MaxSize="Medium" Command="ApplicationCommands.Copy" />
        </bm:BinaryRibbonGroup>
      </bm:BinaryRibbonTabItem>
    </bm:BinaryRibbonBarPanel>
    <DataGrid ItemsSource="{Binding Invoices}" />
  </DockPanel>
</bm:BinaryRibbonWindow>

See also

Members at a glance

Constructors
BinaryRibbonBarPanelCreates a ribbon with no tabs, application menu or quick access toolbar.
Properties
AlignGroupsLeftCommandGets the command that scrolls a ribbon too narrow for its groups back to the first group. Raise it from a control inside the ribbon, or with the ribbon as its CommandTarget.
AlignGroupsRightCommandGets the command that scrolls a ribbon too narrow for its groups on to the last group.
ApplicationMenuGets or sets the application button at the start of the tab row and the menu it opens.
BackgroundColorGets the colour of the contextual tab set the selected tab belongs to.
CanMinimizeGets or sets whether only the tab row is shown, with a tab's commands dropped over the document when it is clicked.
CanUserChangeRibbonLayoutGets or sets whether the user is offered the choice between the classic and the simplified ribbon.
CollapseRibbonBarCommandGets the command that closes the commands a tabs-only ribbon has dropped over the document, by setting IsExpanded to false.
ContextualTabSetGets or sets the contextual tab set on show at the end of the tab row – the tabs that belong to what the user has selected, under a coloured title.
ContextualTabSetsGets the contextual tab sets this ribbon knows about, whether or not one is on show.
CurrentlyVisibleTabItemsGets the tabs on show, ordinary then contextual, leaving out any that are hidden.
DisplayStateGets or sets how much of the ribbon is on screen: the tabs and their commands, the tabs alone, or neither.
IsDisplayStateShortcutEnabledGets or sets whether Ctrl+F1, pressed anywhere in the ribbon's window, calls ToggleDisplayState.
IsExpandedGets or sets whether a tabs-only ribbon has dropped the selected tab's commands over the document.
IsMenuOpenGets or sets a flag the ribbon clears whenever it closes its drop-downs.
IsMinimizedGets whether the ribbon is too narrow to show anything but its title, with its tabs, commands and quick access toolbar hidden.
IsRibbonContextMenuEnabledGets or sets whether right-clicking the ribbon offers its own menu: add to or remove from the quick access toolbar, show the toolbar above or below the ribbon, simplified ribbon, and collapse the ribbon.
IsRibbonControlVisibleGets or sets whether the tab row and the commands are on show; the title and the quick access toolbar stay either way.
IsTouchModeGets whether the ribbon is laid out for touch: small commands on taller rows, with more space between the columns, as in Office's touch mode.
LogicalChildrenGets the application menu, the quick access toolbar and every tab, contextual tabs included.
QuickAccessToolBarGets or sets the quick access toolbar: the small commands kept on show whichever tab is selected.
RibbonLayoutGets or sets whether the ribbon lays its commands out in the classic three rows or on the single line of the simplified ribbon.
SelectedGroupsGets the groups of the selected tab – the groups the ribbon is showing.
SelectedTabIndexGets or sets the position of the selected tab.
SelectedTabItemGets or sets the tab whose groups are on show.
TabsGets the ribbon's tabs, in the order they appear. This is the ribbon's content in XAML.
TitleTextGets or sets the caption shown in bold in the title row, beside the quick access toolbar.
ToolbarPlacementLocationGets or sets whether the quick access toolbar sits above the tabs or below the ribbon.
Methods
AddToQuickAccessToolBarPuts a shortcut to a ribbon command on the quick access toolbar, as the user's "Add to Quick Access Toolbar" does.
ArrangeOverrideArranges the ribbon, and sizes the contextual tab set's title to the width of its tabs.
GetCommandIdGets the name a ribbon command is saved under in GetQuickAccessToolBarState.
GetMaxSizeGets the largest size a command is drawn at.
GetMinSizeGets the smallest size a command shrinks to as its group gives way.
GetQuickAccessSourceGets the ribbon command a quick access toolbar shortcut stands for.
GetQuickAccessToolBarStateDescribes the quick access toolbar – where it sits and which commands the user put on it – as one string to save with the user's settings.
GetResizableSizeGets the sizes a command takes, step by step, as its group gives way.
GetSizeGets the size a ribbon command is drawn at.
IndexOfVisibleTabFinds a tab's position among the tabs on show.
OnApplyTemplateTakes the template's group panels, drop-down and tab container, and puts the tabs into the tab row.
OnContextualTabSetChangedCalled when ContextualTabSet changes; the base implementation swaps the tabs in the tab row.
OnContextualTabSetsChangedCalled when ContextualTabSets changes; the base implementation connects each added set to this ribbon and disconnects each removed one.
OnIsBarExpandedChangedCalled when IsExpanded changes; the base implementation opens or closes the drop-down.
OnLostKeyboardFocusClears IsMenuOpen when the keyboard focus leaves the ribbon.
OnLostMouseCaptureCloses the dropped-down commands of a tabs-only ribbon when the user clicks away from them.
OnPopupCloseCalled when the dropped-down commands of a tabs-only ribbon close. The base implementation clears IsExpanded and releases the mouse; call it when overriding.
OnPopupOpenCalled when a tabs-only ribbon drops its commands over the document. The base implementation sizes the groups to the drop-down and captures the mouse; call it when overriding.
OnPreviewMouseLeftButtonDownReleases the mouse when the ribbon's own background is clicked.
OnPreviewMouseRightButtonUpOpens the ribbon's right-click menu when the right button is released, unless IsRibbonContextMenuEnabled is off.
OnSelectedGroupsChangedCallbackCalled when SelectedGroups changes, after another tab is selected. The base implementation does nothing.
OnSelectedTabIndexChangedCalled when SelectedTabIndex changes; the base implementation updates BackgroundColor.
OnTabItemCollectionChangedCalled when Tabs changes; the base implementation connects each added tab to this ribbon and disconnects each removed one.
OnVisualParentChangedStarts following the width of the ribbon's new parent, so that the groups give way or come back as it is resized.
RemoveFromQuickAccessToolBarTakes a command off the quick access toolbar.
SetCommandIdSets the name a ribbon command is saved under in GetQuickAccessToolBarState.
SetGroupRenderingAlignmentCalled when the groups are scrolled to their start or end, or back to fitting the full width. The base implementation does nothing.
SetMaxSizeSets the largest size a command is drawn at, even with room to spare.
SetMinSizeSets the smallest size a command shrinks to as its group gives way.
SetQuickAccessSourceSets the ribbon command a quick access toolbar shortcut stands for.
SetQuickAccessToolBarStatePuts the quick access toolbar back as GetQuickAccessToolBarState described it.
SetResizableSizeSets the sizes a command takes, step by step, as its group gives way.
SetSizeSets the size a ribbon command is drawn at.
ToggleDisplayStateSwitches between showing the commands and showing only the tabs, as Ctrl+F1 and a double-click on a tab do.
ToggleRibbonLayoutSwitches RibbonLayout between the classic and the simplified ribbon.
VisibleTabFromIndexFinds the tab at a position among the tabs on show.
Events
SelectedTabIndexChangedOccurs when another tab is selected, by the user or through SelectedTabIndex.
Fields
ApplicationMenuPropertyIdentifies the ApplicationMenu dependency property.
BackgroundColorPropertyIdentifies the BackgroundColor dependency property.
CanMinimizePropertyIdentifies the CanMinimize dependency property.
CanUserChangeRibbonLayoutPropertyIdentifies the CanUserChangeRibbonLayout dependency property.
CommandIdPropertyIdentifies the CommandId attached property.
ContextualTabSetPropertyIdentifies the ContextualTabSet dependency property.
DisplayStatePropertyIdentifies the DisplayState dependency property.
IsDisplayStateShortcutEnabledPropertyIdentifies the IsDisplayStateShortcutEnabled dependency property.
IsExpandedPropertyIdentifies the IsExpanded dependency property.
IsMenuOpenPropertyIdentifies the IsMenuOpen dependency property.
IsMinimizedPropertyIdentifies the IsMinimized dependency property.
IsRibbonContextMenuEnabledPropertyIdentifies the IsRibbonContextMenuEnabled dependency property.
IsRibbonControlVisiblePropertyIdentifies the IsRibbonControlVisible dependency property.
MaxSizePropertyIdentifies the MaxSize attached property. The default is BinaryRibbonControlSize.Large.
MinSizePropertyIdentifies the MinSize attached property. The default is BinaryRibbonControlSize.Minimized.
QuickAccessSourcePropertyIdentifies the QuickAccessSource attached property.
QuickAccessToolBarPropertyIdentifies the QuickAccessToolBar dependency property.
ResizableSizePropertyIdentifies the ResizableSize attached property.
RibbonLayoutPropertyIdentifies the RibbonLayout dependency property.
SelectedGroupsPropertyIdentifies the SelectedGroups dependency property.
SelectedTabIndexChangedEventIdentifies the SelectedTabIndexChanged routed event.
SelectedTabIndexPropertyIdentifies the SelectedTabIndex dependency property.
SizePropertyIdentifies the Size attached property. The default is BinaryRibbonControlSize.Large.
TitleTextPropertyIdentifies the TitleText dependency property.
ToolbarPlacementLocationPropertyIdentifies the ToolbarPlacementLocation dependency property.

Constructors

BinaryRibbonBarPanel

public BinaryRibbonBarPanel() : base()

Creates a ribbon with no tabs, application menu or quick access toolbar.

Properties

AlignGroupsLeftCommand static

public static RoutedUICommand AlignGroupsLeftCommand

Gets the command that scrolls a ribbon too narrow for its groups back to the first group. Raise it from a control inside the ribbon, or with the ribbon as its CommandTarget.

AlignGroupsRightCommand static

public static RoutedUICommand AlignGroupsRightCommand

Gets the command that scrolls a ribbon too narrow for its groups on to the last group.

ApplicationMenu

public IBinaryRibbonApplicationMenu ApplicationMenu

Gets or sets the application button at the start of the tab row and the menu it opens.

Value
A BinaryRibbonApplicationMenu or a BinaryRibbonBackstageApplicationMenu; null, the default, shows no application button.

BackgroundColor

public Color BackgroundColor

Gets the colour of the contextual tab set the selected tab belongs to.

Value
That set's BinaryRibbonControlContextualTabSet.BackgroundColor, or Colors.Transparent (the default) while an ordinary tab is selected.

CanMinimize

public bool CanMinimize

Gets or sets whether only the tab row is shown, with a tab's commands dropped over the document when it is clicked.

Value
true for tabs only. The default is false.
Remarks

Kept in step with DisplayState being BinaryRibbonDisplayState.ShowTabsOnly; prefer DisplayState, which also offers auto-hide. A double-click on a tab toggles it.

CanUserChangeRibbonLayout

public bool CanUserChangeRibbonLayout

Gets or sets whether the user is offered the choice between the classic and the simplified ribbon.

Value
The default is true.
Remarks

When false, neither the ribbon's right-click menu nor the window's ribbon display options offer the two layouts; RibbonLayout still works from code.

CollapseRibbonBarCommand static

public static RoutedCommand CollapseRibbonBarCommand

Gets the command that closes the commands a tabs-only ribbon has dropped over the document, by setting IsExpanded to false.

ContextualTabSet

public BinaryRibbonControlContextualTabSet ContextualTabSet

Gets or sets the contextual tab set on show at the end of the tab row – the tabs that belong to what the user has selected, under a coloured title.

Value
The set on show, or null for none. The default is null.
Remarks

Set it when the user selects what the tabs act on, and clear it when they move away; clearing it while one of its tabs is selected selects the first tab.

ContextualTabSets

public Collection<BinaryRibbonControlContextualTabSet> ContextualTabSets

Gets the contextual tab sets this ribbon knows about, whether or not one is on show.

Remarks

Adding a set here connects it to the ribbon but does not show it; show one by assigning it to ContextualTabSet.

CurrentlyVisibleTabItems

public IEnumerable<BinaryRibbonTabItem> CurrentlyVisibleTabItems

Gets the tabs on show, ordinary then contextual, leaving out any that are hidden.

DisplayState

public BinaryRibbonDisplayState DisplayState

Gets or sets how much of the ribbon is on screen: the tabs and their commands, the tabs alone, or neither.

Value
The default is BinaryRibbonDisplayState.ShowTabsAndCommands.
Remarks

The user changes it with Ctrl+F1 (IsDisplayStateShortcutEnabled), a double-click on a tab, the ribbon's right-click menu and the ribbon display options button of a BinaryRibbonWindow. The ribbon saves nothing itself: store the value with the user's other settings to keep it between runs.

Example
<bm:BinaryRibbonBarPanel DisplayState="ShowTabsOnly" IsDisplayStateShortcutEnabled="True" />
See also

IsDisplayStateShortcutEnabled

public bool IsDisplayStateShortcutEnabled

Gets or sets whether Ctrl+F1, pressed anywhere in the ribbon's window, calls ToggleDisplayState.

Value
The default is true.
Remarks

Set it to false when the application gives Ctrl+F1 a meaning of its own. The key is heard on the window, so it works while the focus is in the document.

IsExpanded

public bool IsExpanded

Gets or sets whether a tabs-only ribbon has dropped the selected tab's commands over the document.

Value
true while the commands are dropped down. The default is false.
Remarks

Used while DisplayState is BinaryRibbonDisplayState.ShowTabsOnly: clicking a tab sets it; a command, a click elsewhere or CollapseRibbonBarCommand clears it.

IsMenuOpen

public bool IsMenuOpen

Gets or sets a flag the ribbon clears whenever it closes its drop-downs.

Value
The default is false.
Remarks

Setting it opens nothing; to open the application menu, set BinaryRibbonApplicationMenu.IsOpen.

IsMinimized

public bool IsMinimized

Gets whether the ribbon is too narrow to show anything but its title, with its tabs, commands and quick access toolbar hidden.

Value
true while narrower than 240 logical pixels. The default is false.

IsRibbonContextMenuEnabled

public bool IsRibbonContextMenuEnabled

Gets or sets whether right-clicking the ribbon offers its own menu: add to or remove from the quick access toolbar, show the toolbar above or below the ribbon, simplified ribbon, and collapse the ribbon.

Value
The default is true.
Remarks

Set it to false to give the ribbon a context menu of your own. The quick access toolbar entries are offered only when the ribbon has a QuickAccessToolBar, and the simplified ribbon entry only while CanUserChangeRibbonLayout is on.

IsRibbonControlVisible

public bool IsRibbonControlVisible

Gets or sets whether the tab row and the commands are on show; the title and the quick access toolbar stay either way.

Value
The default is true.
Remarks

BinaryRibbonDisplayState.AutoHide clears it and the other display states set it.

IsTouchMode

public bool IsTouchMode

Gets whether the ribbon is laid out for touch: small commands on taller rows, with more space between the columns, as in Office's touch mode.

Value
true while BinarySkinManager.Density is BinarySkinDensity.Touch. The default is false.
Remarks

The density belongs to the application, not to one ribbon: set BinarySkinManager.Density and every ribbon on screen lays its groups out again, with rows of 32 logical pixels instead of 24. An application offering Office's Touch/Mouse Mode command sets it from there.

Example
// The Touch/Mouse Mode command on the quick access toolbar.
private void OnTouchModeClick(object sender, RoutedEventArgs e)
{
    BinarySkinManager.Density = ribbon.IsTouchMode ? BinarySkinDensity.Standard : BinarySkinDensity.Touch;
}

LogicalChildren

protected override IEnumerator LogicalChildren

Gets the application menu, the quick access toolbar and every tab, contextual tabs included.

QuickAccessToolBar

public BinaryRibbonQuickAccessToolBar QuickAccessToolBar

Gets or sets the quick access toolbar: the small commands kept on show whichever tab is selected.

Value
The toolbar, or null (the default) for none. Without one, the right-click menu offers no "Add to Quick Access Toolbar".

RibbonLayout

public BinaryRibbonLayout RibbonLayout

Gets or sets whether the ribbon lays its commands out in the classic three rows or on the single line of the simplified ribbon.

Value
The default is BinaryRibbonLayout.Classic.
Remarks

In the simplified layout each group is one line of small pictures with captions and has no title; as the window narrows the captions go, and then the group folds into a button whose drop-down shows the commands in the usual rows. Galleries always fold.

Independent of DisplayState: a simplified ribbon can still show only its tabs. The user switches layouts from the right-click menu and the window's ribbon display options, unless CanUserChangeRibbonLayout is off. The ribbon saves nothing itself; store the value with the user's settings to keep it between runs.

See also

SelectedGroups

public Collection<BinaryRibbonGroup> SelectedGroups

Gets the groups of the selected tab – the groups the ribbon is showing.

Value
The selected tab's BinaryRibbonTabItem.AvailableRibbonGroups, or null before a tab is selected.

SelectedTabIndex

public int SelectedTabIndex

Gets or sets the position of the selected tab.

Value
Zero-based, counting the ordinary Tabs first and then the tabs of the ContextualTabSet. The default is 0, the first tab.
Remarks

Each change raises SelectedTabIndexChanged. A position past the last tab, or -1, selects no tab and shows no groups.

SelectedTabItem

public BinaryRibbonTabItem SelectedTabItem

Gets or sets the tab whose groups are on show.

Value
The selected tab, ordinary or contextual; null when SelectedTabIndex points past every tab or is -1.
Remarks

Setting it sets SelectedTabIndex; null, or a tab that is not on this ribbon, sets it to -1 and selects no tab. On a tabs-only ribbon, setting the tab already selected opens or closes its dropped-down commands, as clicking it does.

Tabs

public Collection<BinaryRibbonTabItem> Tabs

Gets the ribbon's tabs, in the order they appear. This is the ribbon's content in XAML.

Remarks

Contextual tabs are not added here but through ContextualTabSet. Add the tabs before the ribbon's template is applied – in XAML, or before the window is shown.

TitleText

public object TitleText

Gets or sets the caption shown in bold in the title row, beside the quick access toolbar.

Value
Usually the document or application name, as text. The default is null: no caption.
Remarks

A BinaryRibbonWindow does not draw its own Window.Title; bind this to it to show it. A long caption ends in an ellipsis.

ToolbarPlacementLocation

public QuickAccessToolbarPlacementLocation ToolbarPlacementLocation

Gets or sets whether the quick access toolbar sits above the tabs or below the ribbon.

Value
The default is QuickAccessToolbarPlacementLocation.Top.
Remarks

The user can move it from the right-click menu. A change is passed on to the toolbar's BinaryRibbonQuickAccessToolBar.ToolBarPlacementLocation.

Methods

AddToQuickAccessToolBar

public void AddToQuickAccessToolBar(UIElement command)

Puts a shortcut to a ribbon command on the quick access toolbar, as the user's "Add to Quick Access Toolbar" does.

Parameters
command
The command on the ribbon. Nothing happens when it is null, is already on the toolbar, or the ribbon has no QuickAccessToolBar.
Remarks

The command stays where it is: the toolbar gets a small BinaryRibbonButton with the command's small picture (or, failing that, its large one) and its tool tip, whose click raises the command's own click and runs its ICommand. To keep the toolbar between runs, give the command a SetCommandId and use GetQuickAccessToolBarState.

Example
ribbon.AddToQuickAccessToolBar(printButton);

ArrangeOverride

protected override Size ArrangeOverride(Size arrangeBounds)

Arranges the ribbon, and sizes the contextual tab set's title to the width of its tabs.

Parameters
arrangeBounds
The space the ribbon was given.
Returns

The space the ribbon used.

GetCommandId static

public static string GetCommandId(DependencyObject element)

Gets the name a ribbon command is saved under in GetQuickAccessToolBarState.

Parameters
element
The command.
Returns

The name, or null when it has none or element is null.

GetMaxSize static

public static BinaryRibbonControlSize GetMaxSize(DependencyObject obj)

Gets the largest size a command is drawn at.

Parameters
obj
The command.
Returns

The size; BinaryRibbonControlSize.Large unless set.

GetMinSize static

public static BinaryRibbonControlSize GetMinSize(DependencyObject obj)

Gets the smallest size a command shrinks to as its group gives way.

Parameters
obj
The command.
Returns

The size; BinaryRibbonControlSize.Minimized unless set.

GetQuickAccessSource static

public static object GetQuickAccessSource(DependencyObject element)

Gets the ribbon command a quick access toolbar shortcut stands for.

Parameters
element
The item on the toolbar.
Returns

The command on the ribbon, or null when the item is not a shortcut (or element is null).

GetQuickAccessToolBarState

public string GetQuickAccessToolBarState()

Describes the quick access toolbar – where it sits and which commands the user put on it – as one string to save with the user's settings.

Returns

The string to hand back to SetQuickAccessToolBarState on the next run, or an empty string when the ribbon has no QuickAccessToolBar.

Remarks

Only shortcuts standing for a command with a SetCommandId are written down; items put on the toolbar directly in XAML are part of the application and are not.

Example
// On closing - QuickAccess is a user setting of type string:
Properties.Settings.Default.QuickAccess = ribbon.GetQuickAccessToolBarState();
Properties.Settings.Default.Save();

// On the next start, once the window is loaded:
ribbon.SetQuickAccessToolBarState(Properties.Settings.Default.QuickAccess);

GetResizableSize static

public static BinaryRibbonControlSizeCollection GetResizableSize(DependencyObject obj)

Gets the sizes a command takes, step by step, as its group gives way.

Parameters
obj
The command.
Returns

The sizes, or null (the default) when the group decides.

GetSize static

public static BinaryRibbonControlSize GetSize(DependencyObject obj)

Gets the size a ribbon command is drawn at.

Parameters
obj
The command.
Returns

The size; BinaryRibbonControlSize.Large unless set.

IndexOfVisibleTab

public int IndexOfVisibleTab(BinaryRibbonTabItem tabItem)

Finds a tab's position among the tabs on show.

Parameters
tabItem
The tab.
Returns

Its zero-based position in CurrentlyVisibleTabItems, or -1 when it is null, hidden or not on this ribbon.

OnApplyTemplate

public override void OnApplyTemplate()

Takes the template's group panels, drop-down and tab container, and puts the tabs into the tab row.

OnContextualTabSetChanged

protected virtual void OnContextualTabSetChanged(DependencyPropertyChangedEventArgs e)

Called when ContextualTabSet changes; the base implementation swaps the tabs in the tab row.

Parameters
e
The old and new sets.

OnContextualTabSetsChanged

protected virtual void OnContextualTabSetsChanged(object sender, NotifyCollectionChangedEventArgs e)

Called when ContextualTabSets changes; the base implementation connects each added set to this ribbon and disconnects each removed one.

Parameters
sender
The collection.
e
The sets added or removed.

OnIsBarExpandedChanged

protected virtual void OnIsBarExpandedChanged(DependencyPropertyChangedEventArgs e)

Called when IsExpanded changes; the base implementation opens or closes the drop-down.

Parameters
e
The old and new values.

OnLostKeyboardFocus

protected override void OnLostKeyboardFocus(KeyboardFocusChangedEventArgs e)

Clears IsMenuOpen when the keyboard focus leaves the ribbon.

Parameters
e
The data for the event.

OnLostMouseCapture

protected override void OnLostMouseCapture(MouseEventArgs e)

Closes the dropped-down commands of a tabs-only ribbon when the user clicks away from them.

Parameters
e
The data for the event.

OnPopupClose

protected virtual void OnPopupClose(object sender, EventArgs e)

Called when the dropped-down commands of a tabs-only ribbon close. The base implementation clears IsExpanded and releases the mouse; call it when overriding.

Parameters
sender
The drop-down.
e
Not used.

OnPopupOpen

protected virtual void OnPopupOpen(object sender, EventArgs e)

Called when a tabs-only ribbon drops its commands over the document. The base implementation sizes the groups to the drop-down and captures the mouse; call it when overriding.

Parameters
sender
The drop-down.
e
Not used.

OnPreviewMouseLeftButtonDown

protected override void OnPreviewMouseLeftButtonDown(MouseButtonEventArgs e)

Releases the mouse when the ribbon's own background is clicked.

Parameters
e
The data for the event.

OnPreviewMouseRightButtonUp

protected override void OnPreviewMouseRightButtonUp(MouseButtonEventArgs e)

Opens the ribbon's right-click menu when the right button is released, unless IsRibbonContextMenuEnabled is off.

Parameters
e
The data for the event.
Remarks

On the button coming up rather than going down, so that the control under the pointer is not left looking pressed.

OnSelectedGroupsChangedCallback

protected virtual void OnSelectedGroupsChangedCallback(DependencyPropertyChangedEventArgs e)

Called when SelectedGroups changes, after another tab is selected. The base implementation does nothing.

Parameters
e
The old and new groups.

OnSelectedTabIndexChanged

protected virtual void OnSelectedTabIndexChanged(DependencyPropertyChangedEventArgs e)

Called when SelectedTabIndex changes; the base implementation updates BackgroundColor.

Parameters
e
The old and new positions.

OnTabItemCollectionChanged

protected virtual void OnTabItemCollectionChanged(object sender, System.Collections.Specialized.NotifyCollectionChangedEventArgs e)

Called when Tabs changes; the base implementation connects each added tab to this ribbon and disconnects each removed one.

Parameters
sender
The collection.
e
The tabs added or removed.

OnVisualParentChanged

protected override void OnVisualParentChanged(DependencyObject oldVisualParent)

Starts following the width of the ribbon's new parent, so that the groups give way or come back as it is resized.

Parameters
oldVisualParent
The previous parent.

RemoveFromQuickAccessToolBar

public void RemoveFromQuickAccessToolBar(UIElement command)

Takes a command off the quick access toolbar.

Parameters
command
The command on the ribbon, or the toolbar item itself. Every shortcut standing for it is removed; nothing happens when it is null or not on the toolbar.

SetCommandId static

public static void SetCommandId(DependencyObject element, string value)

Sets the name a ribbon command is saved under in GetQuickAccessToolBarState.

Parameters
element
The command. Ignored when null.
value
A name unique within the ribbon and the same from one run to the next, such as "Invoice.Send".

SetGroupRenderingAlignment

protected virtual void SetGroupRenderingAlignment(BinaryRibbonBarRenderingAlignment alignment)

Called when the groups are scrolled to their start or end, or back to fitting the full width. The base implementation does nothing.

Parameters
alignment
Where the groups sit after the change.

SetMaxSize static

public static void SetMaxSize(DependencyObject obj, BinaryRibbonControlSize value)

Sets the largest size a command is drawn at, even with room to spare.

Parameters
obj
The command.
value
The size; BinaryRibbonControlSize.Medium stacks a command in rows of three with a small picture and its caption, as Cut, Copy and Format Painter are.

SetMinSize static

public static void SetMinSize(DependencyObject obj, BinaryRibbonControlSize value)

Sets the smallest size a command shrinks to as its group gives way.

Parameters
obj
The command.
value
The size; BinaryRibbonControlSize.Large keeps it large throughout. Not applied on the simplified ribbon, whose single line has no room for large commands.

SetQuickAccessSource static

public static void SetQuickAccessSource(DependencyObject element, object value)

Sets the ribbon command a quick access toolbar shortcut stands for.

Parameters
element
The item on the toolbar. Ignored when null.
value
The command on the ribbon.
Remarks

AddToQuickAccessToolBar sets it; set it yourself only on a shortcut you add to the toolbar by hand, so that the ribbon treats it as that command's shortcut.

SetQuickAccessToolBarState

public void SetQuickAccessToolBarState(string state)

Puts the quick access toolbar back as GetQuickAccessToolBarState described it.

Parameters
state
The saved string. Nothing happens when it is null or empty, or the ribbon has no QuickAccessToolBar.
Remarks

The toolbar's position is restored and a shortcut added for each named command, beside what is already on the toolbar. A name no longer on the ribbon is skipped, and an unreadable position is ignored, so a saved setting that has outlived a command never stops the rest being restored.

SetResizableSize static

public static void SetResizableSize(DependencyObject obj, BinaryRibbonControlSizeCollection value)

Sets the sizes a command takes, step by step, as its group gives way.

Parameters
obj
The command.
value
One size per step, starting with the full-width ribbon; the last applies to every step after it. In XAML, a comma-separated list of size names or their initials, without spaces: "L,M,S".
Remarks

When set, SetMinSize and SetMaxSize are not applied, and the group folds into a single button after as many steps as its longest list.

SetSize static

public static void SetSize(DependencyObject obj, BinaryRibbonControlSize value)

Sets the size a ribbon command is drawn at.

Parameters
obj
The command.
value
Large (picture over caption), medium (small picture beside caption), small (picture alone) or minimised (hidden).
Remarks

A group sets this on its commands whenever it is resized; for a command in a group use SetMaxSize, SetMinSize or SetResizableSize.

ToggleDisplayState

public void ToggleDisplayState()

Switches between showing the commands and showing only the tabs, as Ctrl+F1 and a double-click on a tab do.

Remarks

From BinaryRibbonDisplayState.ShowTabsAndCommands it goes to BinaryRibbonDisplayState.ShowTabsOnly; from either other state it brings the whole ribbon back, so it is always the way back to a ribbon that is out of sight.

ToggleRibbonLayout

public void ToggleRibbonLayout()

Switches RibbonLayout between the classic and the simplified ribbon.

VisibleTabFromIndex

public BinaryRibbonTabItem VisibleTabFromIndex(int index)

Finds the tab at a position among the tabs on show.

Parameters
index
The zero-based position in CurrentlyVisibleTabItems.
Returns

The tab, or null when the position is negative or past the last tab.

Events

SelectedTabIndexChanged

public event RoutedEventHandler SelectedTabIndexChanged

Occurs when another tab is selected, by the user or through SelectedTabIndex.

Remarks

A bubbling routed event; read SelectedTabItem for the new tab.

Fields

ApplicationMenuProperty static

public static readonly DependencyProperty ApplicationMenuProperty

Identifies the ApplicationMenu dependency property.

BackgroundColorProperty static

public static readonly DependencyProperty BackgroundColorProperty

Identifies the BackgroundColor dependency property.

CanMinimizeProperty static

public static readonly DependencyProperty CanMinimizeProperty

Identifies the CanMinimize dependency property.

CanUserChangeRibbonLayoutProperty static

public static readonly DependencyProperty CanUserChangeRibbonLayoutProperty

Identifies the CanUserChangeRibbonLayout dependency property.

CommandIdProperty static

public static readonly DependencyProperty CommandIdProperty

Identifies the CommandId attached property.

Remarks

A command without one can still be put on the quick access toolbar; it is just not remembered between runs, because there is nothing to write down. Only commands directly in a group on one of the ordinary Tabs are found again by SetQuickAccessToolBarState.

Example
<bm:BinaryRibbonButton Content="Send" LargeImage="Images/Send32.png" bm:BinaryRibbonBarPanel.CommandId="Invoice.Send" />

ContextualTabSetProperty static

public static readonly DependencyProperty ContextualTabSetProperty

Identifies the ContextualTabSet dependency property.

DisplayStateProperty static

public static readonly DependencyProperty DisplayStateProperty

Identifies the DisplayState dependency property.

IsDisplayStateShortcutEnabledProperty static

public static readonly DependencyProperty IsDisplayStateShortcutEnabledProperty

Identifies the IsDisplayStateShortcutEnabled dependency property.

IsExpandedProperty static

public static readonly DependencyProperty IsExpandedProperty

Identifies the IsExpanded dependency property.

IsMenuOpenProperty static

public static readonly DependencyProperty IsMenuOpenProperty

Identifies the IsMenuOpen dependency property.

IsMinimizedProperty static

public static readonly DependencyProperty IsMinimizedProperty

Identifies the IsMinimized dependency property.

IsRibbonContextMenuEnabledProperty static

public static readonly DependencyProperty IsRibbonContextMenuEnabledProperty

Identifies the IsRibbonContextMenuEnabled dependency property.

IsRibbonControlVisibleProperty static

public static readonly DependencyProperty IsRibbonControlVisibleProperty

Identifies the IsRibbonControlVisible dependency property.

MaxSizeProperty static

public static readonly DependencyProperty MaxSizeProperty

Identifies the MaxSize attached property. The default is BinaryRibbonControlSize.Large.

MinSizeProperty static

public static readonly DependencyProperty MinSizeProperty

Identifies the MinSize attached property. The default is BinaryRibbonControlSize.Minimized.

QuickAccessSourceProperty static

public static readonly DependencyProperty QuickAccessSourceProperty

Identifies the QuickAccessSource attached property.

QuickAccessToolBarProperty static

public static readonly DependencyProperty QuickAccessToolBarProperty

Identifies the QuickAccessToolBar dependency property.

ResizableSizeProperty static

public static readonly DependencyProperty ResizableSizeProperty

Identifies the ResizableSize attached property.

RibbonLayoutProperty static

public static readonly DependencyProperty RibbonLayoutProperty

Identifies the RibbonLayout dependency property.

SelectedGroupsProperty static

public static readonly DependencyProperty SelectedGroupsProperty

Identifies the SelectedGroups dependency property.

SelectedTabIndexChangedEvent static

public static readonly RoutedEvent SelectedTabIndexChangedEvent

Identifies the SelectedTabIndexChanged routed event.

SelectedTabIndexProperty static

public static readonly DependencyProperty SelectedTabIndexProperty

Identifies the SelectedTabIndex dependency property.

SizeProperty static

public static readonly DependencyProperty SizeProperty

Identifies the Size attached property. The default is BinaryRibbonControlSize.Large.

TitleTextProperty static

public static readonly DependencyProperty TitleTextProperty

Identifies the TitleText dependency property.

ToolbarPlacementLocationProperty static

public static readonly DependencyProperty ToolbarPlacementLocationProperty

Identifies the ToolbarPlacementLocation dependency property.