tags:

views:

43

answers:

2

Our designer is going nuts about this and I just cannot find the right search keywords to figure out how to fix it.

Menus and ContextMenus in WPF have "reveal" animations associated with them. We want to eliminate those without messing with system settings. I managed to pull the template out using Blend but there's nothing in there about animations. Must be inheriting it from somewhere?

Can someone help? Any ideas would be appreciated.

A: 

A Context Menu or a Menu in any Windows Application is managed by Windows Operating System itself. You can go to Display Properties > Appearance to change how a Menu is displayed in the System.

For a WPF Application, you may able to subscribe to the Menu's Opening/Opened event and start a Storyboard to animate it. I am not sure on how to do that but I think that is the way you should be able to change the behavior.

decyclone
WPF does not use Windows to render anything. It has its own presentation layer that it routes directly to DirectX. The animation it is doing is coded into the template or code of the relevant WPF assembly somehow. That's the part I want to override. It is not built into the OS (though the setting it checks when deciding to animate is).
Scott Bilas
So, why is it that when I open a menu in a Wpf Application, an effect that I selected in windows appearance is applied to it?
decyclone
That flag is available to any app. Wpf checks it when deciding whether to animate or not. That's not necessarily the same thing as the OS doing the rendering of the menu.
Scott Bilas
+2  A: 

In short, decyclone is right; it's coming from the OS, but here's why:

The default template for a MenuItem contains the markup and logic for displaying submenus. Look there.

When I opened a copy of a MenuItem template I found no fewer than four ControlTemplates, three Styles, two Brushes, the list went on. Use Blend to "Edit a Copy" of any MenuItem.

Inside the ControlTemplate relevant to a MenuItem's sub-menus is a control primitive called a Popup, declared like this:

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

Note the PopupAnimation property; it points to SystemParameters.MenuPopupAnimationKey. That's the thing that's animating your menu.

This gives you two choices that occur to me, both of which will require that you define a custom template for the MenuItems in your app:

  • Re-configure PART_Popup so that AllowsTranparency="False"; or
  • Re-template MenuItem for your application, removing the PopupAnimation's reference to the OS animation.

You could then author your own triggers for animating how that popup appears.

Rob Perkins
Yes, that's what I meant by it not being an OS feature. WPF is choosing to animate or not based on a query of the OS flag. What I needed to know was where it was buried in what template. Thanks!
Scott Bilas