[英]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.