简体   繁体   中英

WPF ContextMenuOpening event not firing when TextBox has .Text

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?

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

C#:

ContextMenu = null;

or Xaml:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM