繁体   English   中英

wpf contextmenu子菜单放置

[英]wpf contextmenu submenu placement

是什么决定子菜单在上下文菜单中的位置?

我动态创建一个ContextMenu并设置PlacementRectangle,使它出现在屏幕的中心 - 到目前为止一直很好。

一些项目显示子菜单。 但是,子菜单始终默认显示在左侧。 它应默认显示在所选父项的右侧。

我该如何改变?

这是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:如果您使用的是带触摸屏的窗口,菜单会出现在与右手或左手定义的方向相反的位置,这样在使用时菜单不会被手遮挡点击此处查看如何修理它

暂无
暂无

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

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