In This Article

Contextual Tabs

The controls used most often in an application are always available on the ribbon. However, sometimes a specific object is selected in a document (such as a picture, table, or chart) that requires additional controls for proper interaction with the object. This is where contextual tabs come in since they contain the controls that relate to the selected object and are not important enough to display all the time.

Contextual tabs functional the same as standard tabs except that they are associated with a RibbonContextualTabGroup and are only displayed when the associated RibbonContextualTabGroup is visible. The tabs also have an alternate appearance to help differentiate them from standard tabs.

Screenshot

Ribbon with two contextual tabs, one selected

Defining Contextual Tabs

Contextual tab groups are defined in the Ribbon.ContextualTabGroups collection. Each RibbonContextualTabGroup defines a Key property that is used to associate one or more contextual RibbonTabItem instances with that group.

Each RibbonTabItem is defined like standard tabs except an additional ContextualTabGroupKey property is assigned the same value as the corresponding RibbonContextualTabGroup.Key

See the Tabs, Groups, and Control Groups topic for more details on defining standard tabs.

The following code sample shows how to define two contextual tab groups for a ribbon (PictureTools and TableTools) and then associate tabs with the corresponding group:

xmlns:bars="http://schemas.actiprosoftware.com/winfx/xaml/bars"
...
<bars:RibbonContainerPanel>
	<bars:Ribbon>

		<!-- Define ContextualTabGroups -->
		<bars:Ribbon.ContextualTabGroups>
			<bars:RibbonContextualTabGroup Key="PictureTools" />
			<bars:RibbonContextualTabGroup Key="TableTools" />
		</bars:Ribbon.ContextualTabGroups>

		<!-- Standard Tabs (Always Visible) -->
		<bars:RibbonTabItem Key="Home">
			...
		</bars:RibbonTabItem>

		<!-- Picture Tools Contextual Tabs -->
		<bars:RibbonTabItem Key="PictureFormat" ContextualTabGroupKey="PictureTools">
			...
		</bars:RibbonTabItem>

		<!-- Table Tools Contextual Tabs -->
		<bars:RibbonTabItem Key="TableDesign" ContextualTabGroupKey="TableTools">
			...
		</bars:RibbonTabItem>
		<bars:RibbonTabItem Key="Layout" ContextualTabGroupKey="TableTools">
			...
		</bars:RibbonTabItem>

	</bars:Ribbon>
</bars:RibbonContainerPanel>

Showing / Hiding a Contextual Tab Group

The RibbonContextualTabGroup.Visibility property determines the visibility of the associated tab controls.

When the RibbonContextualTabGroup.Visibility property is set to Visible, all its associated tab controls are displayed. Likewise, setting the Visibility property to Collapsed hides all its associated tabs. Multiple contextual tab groups can be visible at the same time.

The following code sample demonstrates one way to show all the tabs associated with a RibbonContextualTabGroup:

using ActiproSoftware.Windows.Controls.Bars;
using System.Linq;
...
Ribbon ribbon;
...
var pictureToolsGroup = ribbon.ContextualTabGroups
	.OfType<RibbonContextualTabGroup>()
	.FirstOrDefault(group => group.Key == "PictureTools")
if (pictureToolsGroup != null)
	pictureToolsGroup.Visibility = System.Windows.Visibility.Visible;
Tip

See the "Contextual Tabs" Bars Ribbon QuickStart of the Sample Browser application for a full demonstration of working with contextual tabs.