Skip to content

Latest commit

 

History

History
39 lines (29 loc) · 2.05 KB

how-to-position-a-custom-context-menu-in-a-richtextbox.md

File metadata and controls

39 lines (29 loc) · 2.05 KB
title ms.date ms.custom description dev_langs helpviewer_keywords ms.assetid
How to: Position a Custom Context Menu in a RichTextBox
03/30/2017
devdivchpfy22
Learn how to position a Custom Context Menu in a RichTextBox.
csharp
vb
custom context menus [WPF], positioning
positioning custom context menus [WPF]
RichTextBox control [WPF], positioning custom context menus
context menus [WPF], positioning
bf77c930-a546-4573-9a56-9af345ba189a

How to: Position a Custom Context Menu in a RichTextBox

This example shows how to position a custom context menu for a xref:System.Windows.Controls.RichTextBox.

When you implement a custom context menu for a RichTextBox, you are responsible for handling the placement of the context menu. By default, a custom context menu is opened at the center of the RichTextBox.

Add a listener for the ContextMenuOpening event

To override the default placement behavior, add a listener for the xref:System.Windows.FrameworkContentElement.ContextMenuOpening event. The following example shows how to do this programmatically.

[!code-csharpRichTextBox_ContextMenu#_AddListener] [!code-vbRichTextBox_ContextMenu#_AddListener]

Implementation of ContextMenuOpening event listener

The following example shows an implementation the corresponding xref:System.Windows.FrameworkContentElement.ContextMenuOpening event listener.

[!code-csharpRichTextBox_ContextMenu#_ListenerBody] [!code-vbRichTextBox_ContextMenu#_ListenerBody]

See also