locked
How to disable a context menu? RRS feed

  • Question

  • I have a button which has a context menu. Now I don't want the context menu to show when the user clicks the button with the right button. I set the Handled parameter to true in the PreviewMouseRightButtonDown and PreviewMouseDown events but the context menu still opens. Is there a way to block it?
    Wednesday, December 17, 2008 9:54 AM

Answers

  • Hi,


    try this
    protected override void OnContextMenuOpening(ContextMenuEventArgs e)
    {
          //statement like
          this.ContextMenu.Visibility = Visibility.Hidden;    

    }

    hope it helps

    Vineeth
    • Proposed as answer by Vineeth Paliath Wednesday, December 17, 2008 10:23 AM
    • Unproposed as answer by Xiangwen Zhu Thursday, December 18, 2008 2:24 AM
    • Marked as answer by Jim Zhou - MSFT Friday, December 19, 2008 9:42 AM
    Wednesday, December 17, 2008 10:04 AM

All replies

  • Hi,


    try this
    protected override void OnContextMenuOpening(ContextMenuEventArgs e)
    {
          //statement like
          this.ContextMenu.Visibility = Visibility.Hidden;    

    }

    hope it helps

    Vineeth
    • Proposed as answer by Vineeth Paliath Wednesday, December 17, 2008 10:23 AM
    • Unproposed as answer by Xiangwen Zhu Thursday, December 18, 2008 2:24 AM
    • Marked as answer by Jim Zhou - MSFT Friday, December 19, 2008 9:42 AM
    Wednesday, December 17, 2008 10:04 AM
  • Vineeth,

    I think this will work. But the problem is that my window contains some user controls from other companies,  I want to disable all context menus in the window under some particular circumstances.  Is there a simple way to do it?
    Thursday, December 18, 2008 2:24 AM