This sample shows how to manipulate the MiniToolbar in order to add contextual content groups.

Inspired by Microsoft Word, the new MiniToolbar is a small version of the full ribbon toolbar providing the most common formatting features. The MiniToolbar appears when text is selected or selected text is right-clicked.

This context sensitive toolbar is very handy for quick formatting tasks without moving the mouse back and forth from the selection to the full ribbon bar.

When right-clicking a selection or an object such as a table or text frame, contextual features are displayed in the MiniToolbar.

The TextControl.ShowMiniToolbar property can be used to control under which circumstances the toolbar should be shown. By default, the MiniToolbar is not shown and must be enabled programmatically to keep applications backwards compatible. In the TextControl.MiniToolbarOpening event, the MiniToolbar can be customized or replaced.

The sample adds a new group to the MiniToolbar to edit hyperlinks when the MiniToolbar is opened by clicking a hyperlink in a document. The following code creates a new RibbonGroup:

[C#]
private Grid CreateEditHyperlinkGroup(int column) {
	Grid rgEditHyperlinkGroup = new Grid();
	Grid.SetRow(rgEditHyperlinkGroup, 0);
	Grid.SetRowSpan(rgEditHyperlinkGroup, 3);
	Grid.SetColumn(rgEditHyperlinkGroup, column);

	rgEditHyperlinkGroup.ColumnDefinitions.Add(new ColumnDefinition() { Width = GridLength.Auto });

	RibbonButton rbtnEditHyperlinkButton = new RibbonButton() { Label = "Edit Hyperlink" };
	Grid.SetRow(rbtnEditHyperlinkButton, 0);
	Grid.SetColumn(rbtnEditHyperlinkButton, 0);

	rbtnEditHyperlinkButton.LargeImageSource = new BitmapImage(new Uri("pack://application:,,,/edithyperlink.png"));
	rbtnEditHyperlinkButton.Click += EditHyperlink_Click;
	rgEditHyperlinkGroup.Children.Add(rbtnEditHyperlinkButton);

	return rgEditHyperlinkGroup;
}
[Visual Basic]
Private Function CreateEditHyperlinkGroup(ByVal column As Integer) As Grid
	Dim rgEditHyperlinkGroup As Grid = New Grid()
	Grid.SetRow(rgEditHyperlinkGroup, 0)
	Grid.SetRowSpan(rgEditHyperlinkGroup, 3)
	Grid.SetColumn(rgEditHyperlinkGroup, column)
	rgEditHyperlinkGroup.ColumnDefinitions.Add(New ColumnDefinition() With {.Width = GridLength.Auto})
	Dim rbtnEditHyperlinkButton As RibbonButton = New RibbonButton() With {.Label = "Edit Hyperlink"}
	rbtnEditHyperlinkButton.LargeImageSource = New BitmapImage(New Uri("Resource/edithyperlink.png", UriKind.Relative))

	Grid.SetRow(rbtnEditHyperlinkButton, 0)
	Grid.SetColumn(rbtnEditHyperlinkButton, 0)

	AddHandler rbtnEditHyperlinkButton.Click, AddressOf Me.EditHyperlink_Click

	rgEditHyperlinkGroup.Children.Add(rbtnEditHyperlinkButton)
	Return rgEditHyperlinkGroup
End Function

This group is added in the TextControl.TextMiniToolbarInitialized event:

[C#]
private void textControl1_TextMiniToolbarInitalized(object sender, TXTextControl.WPF.MiniToolbarInitializedEventArgs e) {
	e.MiniToolbar.Container.Children.Add(CreateRibbonGroupSeperator(3));
	e.MiniToolbar.Container.ColumnDefinitions.Add(new ColumnDefinition() { Width = GridLength.Auto });
	e.MiniToolbar.Container.Children.Add(CreateEditHyperlinkGroup(4));
}
[Visual Basic]
Private Sub textControl1_TextMiniToolbarInitalized(ByVal sender As Object, ByVal e As TXTextControl.WPF.MiniToolbarInitializedEventArgs)
	e.MiniToolbar.Container.Children.Add(CreateRibbonGroupSeperator(3))
	e.MiniToolbar.Container.ColumnDefinitions.Add(New ColumnDefinition() With {.Width = GridLength.Auto})
	e.MiniToolbar.Container.Children.Add(CreateEditHyperlinkGroup(4))
End Sub

In the TextControl.MiniToolbarOpening event, contextual groups are hidden dynamically:

[C#]
private void textControl1_MiniToolbarOpening(object sender, TXTextControl.WPF.MiniToolbarOpeningEventArgs e) {
	if (e.MiniToolbar is TextMiniToolbar) {
		e.MiniToolbar.Container.Children[2].Visibility = System.Windows.Visibility.Visible;
		e.MiniToolbar.Container.Children[3].Visibility = 
		e.MiniToolbar.Container.Children[4].Visibility = 

		(e.MiniToolbarContext & ContextMenuLocation.TextField) == ContextMenuLocation.TextField &&
		textControl1.HypertextLinks.GetItem() != null ? System.Windows.Visibility.Visible : System.Windows.Visibility.Collapsed;
	}	
}
[Visual Basic]
Private Sub textControl1_MiniToolbarOpening(ByVal sender As Object, ByVal e As TXTextControl.WPF.MiniToolbarOpeningEventArgs)
	If (TypeOf e.MiniToolbar Is TextMiniToolbar) Then
		e.MiniToolbar.Container.Children(2).Visibility = System.Windows.Visibility.Visible
		e.MiniToolbar.Container.Children(3).Visibility = Not (((e.MiniToolbarContext And ContextMenuLocation.TextField) _
					= ContextMenuLocation.TextField) _
					AndAlso (Not (textControl1.HypertextLinks.GetItem) Is Nothing))
		e.MiniToolbar.Container.Children(4).Visibility = Not (((e.MiniToolbarContext And ContextMenuLocation.TextField) _
					= ContextMenuLocation.TextField) _
					AndAlso (Not (textControl1.HypertextLinks.GetItem) Is Nothing))
	End If
End Sub

When right-clicking a hyperlink in the sample, the MiniToolbar is shown with the new contextual ribbon group: