如何禁用 WPF ContextMenu 动画? [英] How to disable WPF ContextMenu animations?

查看:61
本文介绍了如何禁用 WPF ContextMenu 动画?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在努力寻找需要调整的部分,以使 WPF 中的 ContextMenus 在它们出现/消失时停止动画.

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

据我所知,WPF 创建了一个 Popup 来托管 ContextMenu.Popup 查看其 PopupAnimation 属性并决定如何设置动画.我想要做的是始终将其设置为无".

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".

我已尝试使用将 PopupAnimation 设置为 None 的 Popup 的 TargetType 设置全局未命名样式,但这不起作用.如果我打破 System.Windows.Controls.Primitives.Popup.SetupAnimations 我可以看到动画类型仍然设置为淡入淡出.我猜它还没有机会应用样式..

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..

我尝试挂钩 ContextMenuOpening,但无法访问我能找到的弹出窗口.

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

我还能尝试什么?

请注意,这是我问的另一个问题的第二部分 这里.那里的建议对菜单和我们拥有的所有其他动画效果很好,但唯一的例外是 ContextMenus.它们基于代码中的属性而不是模板进行动画处理.我通过使用此处给出的建议拉出 ContextMenu 模板来验证这一点.

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.

推荐答案

我也一直在为此苦苦挣扎.我发现解决方案是覆盖"控制弹出动画的系统参数.

I've been struggling with this too. I've found that the solution is to "override" the system parameter that control popup animation.

通过像这样定义一个资源(可能在你的 Themes\Generic.xaml 中)来做到这一点:

Do this by defining a resource (perhaps in your Themes\Generic.xaml) like this:

<PopupAnimation x:Key="{x:Static SystemParameters.MenuPopupAnimationKey}">None</PopupAnimation>

这篇关于如何禁用 WPF ContextMenu 动画?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆