Built-In Ribbon Tabs
A WPF ribbon for a word processor needs no command code of its own: TX Text Control .NET for WPF ships twelve ribbon tabs that format text, insert tables and images, set up pages, check spelling, protect documents and design mail merge templates in the connected TextControl. They are regular tabs of the WPF Ribbon control of Microsoft, so you combine them with tabs of your own in one ribbon. Read on for what each tab contains, how its items are named, and how you rename, hide or remove items, groups and tabs.
A first ribbon application is built in Create a WPF Ribbon Application, and Connecting Ribbon Tabs in XAML explains how the tabs are declared and connected.

How the Tabs Fit Into a WPF Ribbon
The ribbon itself is not a TX Text Control class. It is System.Windows.Controls.Ribbon.Ribbon from the assembly System.Windows.Controls.Ribbon, which WPF provides, usually hosted in a RibbonWindow. TX Text Control adds the tabs:
- Each tab derives from
System.Windows.Controls.Ribbon.RibbonTaband must be placed in aRibbon. Its groups areRibbonGroupobjects in itsItemscollection, and their buttons areRibbonButton,RibbonToggleButton,RibbonSplitButtonand other controls of the same WPF namespace. - Each tab is connected on its own. The
TextControlhas one string property per tab, such as RibbonFormattingTab, which holds the name of the tab element. A tab that is not named in such a property does nothing. - In the toolbox, the tabs are in the TX Text Control 34.0 tab, and you drag them into the
Ribbonelement of the XAML.
The Predefined Tabs
The tab titles in the first column are those of the TX Words sample; you set the title of a tab with its Header property. The groups are the values of the tab's RibbonItem enumeration that end in Group:
| Tab | Class | Groups |
|---|---|---|
| Home | RibbonFormattingTab | TXITEM_ClipboardGroup, TXITEM_FontGroup, TXITEM_ParagraphGroup, TXITEM_StylesGroup, TXITEM_EditingGroup |
| Insert | RibbonInsertTab | TXITEM_PageGroup, TXITEM_TableGroup, TXITEM_IllustrationsGroup, TXITEM_LinksGroup, TXITEM_HeaderFooterGroup, TXITEM_TextGroup, TXITEM_SymbolsGroup |
| Page Layout | RibbonPageLayoutTab | TXITEM_PageSetupGroup, TXITEM_ColumnsAndBreaksGroup, TXITEM_PageBackgroundAndBordersGroup |
| View | RibbonViewTab | TXITEM_DocumentViewsGroup, TXITEM_ZoomGroup, TXITEM_ToolbarsGroup, TXITEM_ShowGroup |
| References | RibbonReferencesTab | TXITEM_FootnotesGroup, TXITEM_TableOfContentsGroup, TXITEM_TableOfContentsPropertiesGroup, TXITEM_ParagraphStructureLevelsGroup |
| Proofing | RibbonProofingTab | TXITEM_SpellingAndHyphenationGroup, TXITEM_ProofingSettingsGroup, TXITEM_CommentsGroup, TXITEM_TrackChangesGroup, TXITEM_LanguageGroup |
| Permissions | RibbonPermissionsTab | TXITEM_RestrictFormattingGroup, TXITEM_RestrictEditingGroup, TXITEM_ReadOnlyExceptionsGroup, TXITEM_EditRestrictedDocumentGroup |
| Form Fields | RibbonFormFieldsTab | TXITEM_InsertFormFieldsGroup, TXITEM_EditFormFieldsGroup, TXITEM_FormValidationGroup, TXITEM_FormFieldPropertiesGroup and a properties group per field type |
| Reporting | RibbonReportingTab | TXITEM_DataSourceGroup, TXITEM_MergeFieldsGroup, TXITEM_MergeBlocksGroup, TXITEM_ViewGroup |
| Table Layout | RibbonTableLayoutTab | TXITEM_TableLayoutGroup, TXITEM_RowsAndColumnsGroup, TXITEM_MergeGroup, TXITEM_BordersAndBackgroundGroup, TXITEM_TableAlignmentGroup, TXITEM_TablePropertiesGroup |
| Formulas | RibbonFormulaTab | TXITEM_FormulaGroup, TXITEM_NumberFormatGroup, TXITEM_FormulaSettingsGroup |
| Frame Formatting | RibbonFrameLayoutTab | TXITEM_ObjectArrangeGroup, TXITEM_ObjectSizeGroup, a borders or colors group for text frames, drawings and barcodes, TXITEM_ObjectPropertiesGroup, TXITEM_Signature_SignerInfoGroup |
Differences from the Windows Forms ribbon are worth knowing if you port an application: there is no chart layout tab and no Chart button on the Insert tab, and the groups have no dialog box launcher items. Instead, the Home tab has the items TXITEM_CharacterFormatting in the Font group and TXITEM_ParagraphFormatting in the Paragraph group.
Some tabs have properties beyond the connection:
- Reporting. RibbonReportingTab.DataSourceManager is the object behind the data source commands; see Reporting Ribbon and Dialog Boxes.
- Permissions. RegisteredUserNames fills the list of users for read-only exceptions, and AllowAddingUserNames decides whether users add names to it. See Document Protection and Editable Regions.
- Home, Proofing, Form Fields and Reporting. Properties such as
FindSidebarconnect buttons to sidebars; see Sidebar and Panels. - Form Fields. The Form Validation group,
TXITEM_FormValidationGroup, turns form validation on and manages the conditional instructions of a form, rules that validate, enable or fill form fields depending on other fields. Form Fields and Conditional Instructions shows the group at work, and Conditional Instructions describes every condition and instruction.

Find an Item by Its Name
Every item of a predefined tab has a Name, and the name is the string of a value of the tab's RibbonItem enumeration, for example RibbonFormattingTab.RibbonItem. WPF's FrameworkElement.FindName on the tab returns the item, or null if the tab does not contain it:
- Groups and items. Values that end in
Groupidentify aRibbonGroup; the others a button, combo box, gallery or text box. - Drop-down items. The entries of drop-down menus are values of the second enumeration,
RibbonDropDownItem, for example RibbonFormattingTab.RibbonDropDownItem. They identify resources for the ResourceProvider. - The type of the result.
FindNamereturnsobject. Cast it to the WPF ribbon class of the item, or toFrameworkElementwhen you only move, hide or remove it.
Change and Remove Items
The following code runs in the Loaded event handler of the TextControl, named textControl in the XAML, when the tabs and their items exist. It replaces the Bold button with a button of your own and hides the Shape button of the Insert tab:
using System.Windows;
using System.Windows.Controls;
using System.Windows.Controls.Ribbon;
using TXTextControl.WPF;
private void TextControl_Loaded(object sender, RoutedEventArgs e)
{
// Replace the Bold button with a button of your own
FrameworkElement boldButton = ribbonFormattingTab.FindName(
RibbonFormattingTab.RibbonItem.TXITEM_Bold.ToString()) as FrameworkElement;
if (boldButton?.Parent is ItemsControl parent)
{
int index = parent.Items.IndexOf(boldButton);
parent.Items.Remove(boldButton);
parent.Items.Insert(index, new RibbonButton() { Label = "Strong" });
}
// Hide the Shape button, but keep it in the tab
if (ribbonInsertTab.FindName(
RibbonInsertTab.RibbonItem.TXITEM_InsertShape.ToString()) is FrameworkElement shapeButton)
{
shapeButton.Visibility = Visibility.Collapsed;
}
}
The code works as follows:
- The value's
ToString()is the name thatFindNamelooks for.ribbonFormattingTabandribbonInsertTabare thex:Namevalues of the tabs in the XAML. - The item's
Parentis theItemsControlthat holds it. Removing it there and inserting a newRibbonButtonat the same index is the pattern the reference page ofRibbonFormattingTabuses.Labelis the text of a WPFRibbonButton, and itsClickevent runs your command. Visibility.Collapsedhides an item without removing it, so you can show it again later.
Remove Groups and Tabs
A group is removed from the Items collection of its tab, and a tab from the Items collection of the ribbon:
// Remove the Font group from the Home tab
if (ribbonFormattingTab.FindName(
RibbonFormattingTab.RibbonItem.TXITEM_FontGroup.ToString()) is RibbonGroup fontGroup)
{
ribbonFormattingTab.Items.Remove(fontGroup);
}
// Remove the Insert tab from the ribbon
ribbon.Items.Remove(ribbonInsertTab);
A tab that no user needs is better left out of the XAML. Removing in code suits tabs and groups that depend on the user, such as the Permissions tab for users who may not change the protection of a document.
Show Tabs Only in Context
The Table Layout, Formulas and Frame Formatting tabs are meant to appear only while the user works in a table or on a frame. WPF's RibbonContextualTabGroup provides this: a tab belongs to the group whose Header equals the tab's ContextualTabGroupHeader, and your code sets the group's Visibility. Add a Table Tools Tab in the tutorial Create a WPF Ribbon Application builds a Table Tools group step by step: a handler of InputPositionChanged shows it while Tables.GetItem returns a table. The Formulas tab joins the same group with ContextualTabGroupHeader="Table Tools".
Show Frame Tools While a Frame Is Selected
The TX Words sample puts the Frame Formatting tab into a second contextual group, Frame Tools. Here the trigger is not the input position but the selection of a frame, which is an image, a text frame, a barcode or a drawing. The tab and the group are declared like the table tabs, with a group color of its own:
<WPF:RibbonFrameLayoutTab x:Name="ribbonFrameLayoutTab" Header="Frame Formatting"
ContextualTabGroupHeader="Frame Tools"/>
<Ribbon.ContextualTabGroups>
<RibbonContextualTabGroup x:Name="frameToolsGroup" Header="Frame Tools"
Background="#66FF00FF" Visibility="Collapsed"/>
</Ribbon.ContextualTabGroups>
Both groups go into the same Ribbon.ContextualTabGroups element when the ribbon has table and frame tools. Two handlers show and hide the group:
using System.Windows;
using TXTextControl;
private void TextControl_FrameSelected(object sender, FrameEventArgs e)
{
// A frame is selected: show Frame Tools
frameToolsGroup.Visibility = Visibility.Visible;
}
private void TextControl_FrameDeselected(object sender, FrameEventArgs e)
{
// The frame lost the selection: hide Frame Tools again
frameToolsGroup.Visibility = Visibility.Collapsed;
}
The code works as follows:
- FrameSelected occurs when the user selects a frame, and FrameDeselected when it is deselected. Attach them with
FrameSelected="TextControl_FrameSelected"andFrameDeselected="TextControl_FrameDeselected"on theTextControlelement. - Both handlers receive a FrameEventArgs, whose Frame property is the frame concerned. Check its type if a group should appear for images only, for example.
- The
RibbonFrameLayoutTabmust be connected with the RibbonFrameLayoutTab property of theTextControl, like every other tab.
Next Steps
- Connecting Ribbon Tabs in XAML: the XAML of a complete ribbon window and the connection properties.
- Custom Tabs and Commands: tabs and buttons of your own, the application menu and the Quick Access Toolbar.
- Rulers and Status Bar: the bars that the View tab shows and hides.
- Ribbon Tabs, Toolbars, Rulers, and Status Bar: the overview of all command controls.