tags:

views:

26

answers:

1

I'm trying to hunt down what bit I need to tweak to get ContextMenus in WPF to stop animating when they appear/disappear.

From what I can tell, WPF creates a Popup to host the ContextMenu. The Popup looks at its PopupAnimation property and decides how to animate. What I want to do is always have that set to "None".

I've tried setting a global unnamed style with a TargetType of Popup that sets PopupAnimation to None but this does not work. If I break in System.Windows.Controls.Primitives.Popup.SetupAnimations I can see that the animation type is still set to Fade. I'm guessing that it hasn't had a chance to apply styles yet..

I've tried hooking ContextMenuOpening but there's no access to a Popup in there that I could find.

What else could I try?

Note that this is sort of the second part of another question I asked here. The advice there worked great for menus and everything else we had that was animating, but the one exception has been ContextMenus. They animate based on properties in code, not a template. I verified this by pulling the ContextMenu template out using the advice given here.

A: 

Hi,

In your previous question, Rob showed you the reason why it acts like that. Can you not create a new ControlTemplate for your ContextMenu and set PopupAnimation property to None like the following :

               <Popup x:Name="PART_Popup" 
                   AllowsTransparency="true" 
                   Focusable="false" 
                   HorizontalOffset="-2" 
                   IsOpen="{Binding IsSubmenuOpen, 
                            RelativeSource={RelativeSource TemplatedParent}}" 
                   PopupAnimation="None" 
                   Placement="Right" 
                   VerticalOffset="-3">

You could create your own ContextMenu or apply a ControlTemplate using the shown code to specific instances.

decyclone
As I said above, ContextMenu is different. What Rob was explaining was a binding inside of the MenuItem template that directly asked the OS for a flag whether it should animate or not. In this case, there is code in the Popup class doing the work. And while the template for a MenuItem includes the animation which is easy to disable in a template override, ContextMenu is put inside of that Popup by something inside of WPF. I need a way to access its containing Popup at construction time to kill the animation, but can't figure out where it comes from or how to alter it.
Scott Bilas