WPF Custom TextBox ContextMenuOpening Problem

Posted by Tom Allen on Stack Overflow See other posts from Stack Overflow or by Tom Allen
Published on 2010-04-21T08:23:55Z Indexed on 2010/04/21 8:33 UTC
Read the original article Hit count: 811

Filed under:
|

I've got an issue with a custom control that I've written not firing it's ContextMenuOpening event when I hook it up programatically. The control is basically a wrapper for the standard TextBox:

public class MyTextBox : TextBox
{
    public MyTextBox()
    {
        this.ContextMenuOpening += new ContextMenuEventHandler(MyTextBox_ContextMenuOpening);
    }

    void MyTextBox_ContextMenuOpening(object sender, ContextMenuEventArgs e)
    {
        MessageBox.Show("ContextMenuOpening event fired");
    }
}

There's nothing suspect either about the XAML:

<local:MyTextBox Height="25" Width="300"/>

For some reason though, I can never get the event to fire. I'm trying to intercept the context menu so I can alter it (it's context sensitive) and really am trying to avoid having to hook up the event everywhere the control is used - surely this is possible?

© Stack Overflow or respective owner

Related posts about wpf

Related posts about contextmenu