none
How to disable the popup fade effect on ContextMenus?

    Question

  • Hi,

    I am trying to figure out how to disable the popup fade effect on ContextMenus. Is this possible to do using a ContextMenu Style or ControlTemplate? I can't find any info on this.

    Thanks,
    Peter

    Peter E
    Wednesday, August 13, 2008 8:20 AM

Answers

  • Hi,

    This turned out to be pretty simple once I figured out how a ContextMenu is connected to a Popup.  Here's the code from the sample app I created:

        public partial class Window1 : Window
        {
            public Window1()
            {
                InitializeComponent();
                ContextMenu myMenu = new ContextMenu();
                MenuItem myItem = new MenuItem();
                myItem.Header = "test";
                myMenu.Items.Add(myItem);
                myMenu.IsVisibleChanged += new DependencyPropertyChangedEventHandler(myMenu_IsVisibleChanged);

                this.ContextMenu = myMenu;
            }

            void myMenu_IsVisibleChanged(object sender, DependencyPropertyChangedEventArgs e)
            {
                ContextMenu menu = sender as ContextMenu;
                Popup myParentPopup = menu.Parent as Popup;
                myParentPopup.PopupAnimation = PopupAnimation.None;
            }
        }



    Andre
    • Marked as answer by Marco Zhou Tuesday, August 19, 2008 10:43 AM
    Wednesday, August 13, 2008 9:04 PM
    Moderator

All replies

  • Hi,

    This turned out to be pretty simple once I figured out how a ContextMenu is connected to a Popup.  Here's the code from the sample app I created:

        public partial class Window1 : Window
        {
            public Window1()
            {
                InitializeComponent();
                ContextMenu myMenu = new ContextMenu();
                MenuItem myItem = new MenuItem();
                myItem.Header = "test";
                myMenu.Items.Add(myItem);
                myMenu.IsVisibleChanged += new DependencyPropertyChangedEventHandler(myMenu_IsVisibleChanged);

                this.ContextMenu = myMenu;
            }

            void myMenu_IsVisibleChanged(object sender, DependencyPropertyChangedEventArgs e)
            {
                ContextMenu menu = sender as ContextMenu;
                Popup myParentPopup = menu.Parent as Popup;
                myParentPopup.PopupAnimation = PopupAnimation.None;
            }
        }



    Andre
    • Marked as answer by Marco Zhou Tuesday, August 19, 2008 10:43 AM
    Wednesday, August 13, 2008 9:04 PM
    Moderator
  • So the PopUp is actually a parent to the ContextMenu? I guess that this makes it bit hard do disable this behavior for my app globally, defining a Style and ControlTemplate for the ComboBox.

    //Peter

    Peter E
    Friday, August 15, 2008 6:48 AM