How to disable WPF ContextMenu animations?

前端 未结 3 1027
伪装坚强ぢ
伪装坚强ぢ 2020-12-15 22:57

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

相关标签:
3条回答
  • 2020-12-15 23:32

    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);
    
    0 讨论(0)
  • 2020-12-15 23:35

    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.

    0 讨论(0)
  • 2020-12-15 23:46

    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>
    
    0 讨论(0)
提交回复
热议问题