简体   繁体   English

wpf contextmenu子菜单放置

[英]wpf contextmenu submenu placement

What determines the placement of submenus in a contextmenu? 是什么决定子菜单在上下文菜单中的位置?

I create a ContextMenu dynamically and set the PlacementRectangle so that it appears in the center of the screen - so far so good. 我动态创建一个ContextMenu并设置PlacementRectangle,使它出现在屏幕的中心 - 到目前为止一直很好。

Some of the items show a submenu. 一些项目显示子菜单。 However the submenu always defaults to showing on the left. 但是,子菜单始终默认显示在左侧。 It should default to showing on the right of the parent item selected. 它应默认显示在所选父项的右侧。

How do I change this? 我该如何改变?

This is the default for MenuItem.TopLevelItemTemplateKey 这是MenuItem.TopLevelItemTemplateKey的默认值

<Popup x:Name="PART_Popup" AllowsTransparency="True" Focusable="False" IsOpen="{Binding IsSubmenuOpen, RelativeSource={RelativeSource TemplatedParent}}" PopupAnimation="{DynamicResource {x:Static SystemParameters.MenuPopupAnimationKey}}" Placement="Bottom" >

Now this it default for MenuItem.SubmenuHeaderTemplateKey 现在这是MenuItem.SubmenuHeaderTemplateKey默认值

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

Edit 1: Look for some custom style for popup defined in your App.xaml file that may be setting by default the location of all the popup in the center of the screen 编辑1:查找App.xaml文件中定义的弹出窗口的一些自定义样式,默认情况下可以设置屏幕中心所有弹出窗口的位置

Edit 2: If you are using windows with touch screen the menu appears in a position opposite to the orientation defined for right handed or left handed, this is so that the menu is not obscured by your hand when using it click here to see how to fix it 编辑2:如果您使用的是带触摸屏的窗口,菜单会出现在与右手或左手定义的方向相反的位置,这样在使用时菜单不会被手遮挡点击此处查看如何修理它

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM