0
votes

I have a user control ultimately derived from a TextBox.

I want to suppress the right-click context menu for this control.

I've added a code to intercept the ContextMenuOpening event on the user control and to suppress the context menu:

ContextMenuOpening +=  HandleIt;
...
private void HandleIt(object sender, ContextMenuEventArgs e)
{
    e.Handled = true;
}

When the control is empty (no .Text) this works fine.

However, when the control has some text, HandleIt() is not even called.

Am I doing something wrong?

How do I suppress the context menu for this user control under all conditions?

1
How can "a user control be ultimately derived from a TextBox"? - mm8

1 Answers

0
votes

How do I suppress the context menu for this user control under all conditions?

C#:

ContextMenu = null;

or Xaml:

<TextBox ContextMenu="{x:Null}" />