什么决定子菜单在上下文菜单中的位置?
我动态创建一个ContextMenu并设置PlacementRectangle,使其显示在屏幕的中心 - 到目前为止一直很好。
部分项目显示子菜单。 但是,子菜单始终默认显示在左侧。 它应默认显示在所选父项的右侧。
如何更改此内容?
答案 0 :(得分:0)
这是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" >
现在这是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">
编辑1: 查找App.xaml文件中定义的弹出窗口的一些自定义样式,默认情况下可以设置屏幕中心所有弹出窗口的位置
编辑2: 如果您使用带触摸屏的窗口,菜单会出现在与右手或左手定义的方向相反的位置,这样在使用时菜单不会被手遮挡 click here to see how to fix it