wpf-devexpress-dot-xpf-dot-richedit-dot-menu.md
An action that removes a bar item associated with a specific command. This action also deletes all links to this bar item from bars, menus, submenus, and other link holders.
Namespace : DevExpress.Xpf.RichEdit.Menu
Assembly : DevExpress.Xpf.RichEdit.v25.2.dll
NuGet Package : DevExpress.Wpf.RichEdit
public class RemoveRichEditCommandAction :
RemoveBarItemLinkAction
Public Class RemoveRichEditCommandAction
Inherits RemoveBarItemLinkAction
Add a RemoveRichEditCommandAction instance to the PopupMenuShowingEventArgs.Customizations collection to remove command links for the command defined by the RemoveRichEditCommandAction.Id property.
RemoveRichEditCommandAction removes a bar item from the BarManager.Items collection and deletes all links to the bar item from link holders (bars, ribbon, menus, and so on).
The example below customizes the Text context menu as follows:
<dxre:RichEditControl Name="richTextEditor"
PopupMenuShowing="richTextEditor_PopupMenuShowing">
using DevExpress.XtraRichEdit.API.Native;
using DevExpress.Xpf.RichEdit;
using DevExpress.Xpf.Bars;
using DevExpress.Xpf.RichEdit.Menu;
using DevExpress.XtraRichEdit.Commands;
// ...
private void richTextEditor_PopupMenuShowing(object sender, PopupMenuShowingEventArgs e) {
// Check whether the event is raised for document text.
if (e.MenuType == RichEditMenuType.Text) {
// Create a menu item to insert a picture
// and bind this item to the Rich Text Editor's command.
e.Customizations.Add(new BarButtonItem() {
Command = RichEditUICommand.InsertFloatingPicture,
Content = "Insert Picture",
CommandParameter = richTextEditor
});
// Create a custom menu item to highlight selected text.
var menuItem = new BarButtonItem() {
Name = "highlightSelectionItem",
Content = "Highlight Selection"
};
menuItem.ItemClick += MenuItem_ItemClick; ;
e.Customizations.Add(menuItem);
}
// Remove the "Increase Indent" item from the menu.
e.Customizations.Add(new RemoveRichEditCommandAction() {
Id = RichEditCommandId.IncreaseIndent
});
// Remove the "Decrease Indent" item from the menu.
e.Customizations.Add(new RemoveRichEditCommandAction() {
Id = RichEditCommandId.DecreaseIndent
});
}
private void MenuItem_ItemClick(object sender, ItemClickEventArgs e) {
var selectedRanges = richTextEditor.Document.Selections;
foreach (var range in selectedRanges) {
var charProps = richTextEditor.Document.BeginUpdateCharacters(range);
charProps.BackColor = System.Drawing.Color.Yellow;
richTextEditor.Document.EndUpdateCharacters(charProps);
}
}
Imports DevExpress.XtraRichEdit.API.Native
Imports DevExpress.Xpf.RichEdit
Imports DevExpress.Xpf.Bars
Imports DevExpress.Xpf.RichEdit.Menu
Imports DevExpress.XtraRichEdit.Commands
' ...
Private Sub richTextEditor_PopupMenuShowing(ByVal sender As Object, ByVal e As PopupMenuShowingEventArgs)
' Check whether the event is raised for document text.
If e.MenuType = RichEditMenuType.Text Then
' Create a menu item to insert a picture
' and bind this item to the Rich Text Editor's command.
e.Customizations.Add(New BarButtonItem() With {
.Command = RichEditUICommand.InsertFloatingPicture,
.Content = "Insert Picture",
.CommandParameter = richTextEditor
})
' Create a custom menu item to highlight selected text.
Dim menuItem As New BarButtonItem() With {
.Name = "highlightSelectionItem",
.Content = "Highlight Selection"
}
menuItem.ItemClick += MenuItem_ItemClick
e.Customizations.Add(menuItem)
End If
' Remove the "Increase Indent" item from the menu.
e.Customizations.Add(New RemoveRichEditCommandAction() With {
.Id = RichEditCommandId.IncreaseIndent})
' Remove the "Decrease Indent" item from the menu.
e.Customizations.Add(New RemoveRichEditCommandAction() With {
.Id = RichEditCommandId.DecreaseIndent})
End Sub
Private Sub MenuItem_ItemClick(ByVal sender As Object, ByVal e As ItemClickEventArgs)
Dim selectedRanges As SelectionCollection = richTextEditor.Document.Selections
For Each range As DocumentRange In selectedRanges
Dim charProps As CharacterProperties = richTextEditor.Document.BeginUpdateCharacters(range)
charProps.BackColor = System.Drawing.Color.Yellow
richTextEditor.Document.EndUpdateCharacters(charProps)
Next range
End Sub
The following code snippet (auto-collected from DevExpress Examples) contains a reference to the RemoveRichEditCommandAction class.
Note
The algorithm used to collect these code examples remains a work in progress. Accordingly, the links and snippets below may produce inaccurate results. If you encounter an issue with code examples below, please use the feedback form on this page to report the issue.
wpf-rich-text-editor-customize-context-menu/CS/ContextMenuCustomization/MainWindow.xaml#L41
<dxre:RichEditMenuCustomization>
<dxre:RemoveRichEditCommandAction Id="{x:Static dxrecore:RichEditCommandId.CutSelection}" />
<dxb:BarButtonItemLink dxb:BarItemLinkActionBase.ItemLinkIndex="0">
Show 11 items
Object DispatcherObject DependencyObject ContentElement FrameworkContentElement DXFrameworkContentElement BarManagerControllerActionBase BarItemLinkActionBase UpdateBarItemLinkActionBase RemoveBarItemLinkAction RemoveRichEditCommandAction
See Also
RemoveRichEditCommandAction Members