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
I spent a good half hour trying to figure out how to do this in code - I'm sure its obvious if you know the framework better:
var app = new Application();
app.Resources.Add(SystemParameters.MenuPopupAnimationKey, PopupAnimation.None);
app.Run(myThing);
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.
I've been struggling with this too. I've found that the solution is to "override" the system parameter that control popup animation.
Do this by defining a resource (perhaps in your Themes\Generic.xaml
) like this:
<PopupAnimation x:Key="{x:Static SystemParameters.MenuPopupAnimationKey}">None</PopupAnimation>