Bol*_*ock 23 .net wpf xaml contextmenu
我有一个带有默认命令的按钮和一个用于其他可用命令的上下文菜单:
<Button Content="Do this" Height="23" Width="75" Command="local:MyCommands.ThisCommand">
<Button.ContextMenu>
<ContextMenu>
<MenuItem Header="Do this" Command="local:MyCommands.ThisCommand" />
<MenuItem Header="Do that" Command="local:MyCommands.ThatCommand" />
</ContextMenu>
</Button.ContextMenu>
</Button>
Run Code Online (Sandbox Code Playgroud)
默认情况下,上下文菜单从光标的热点开始显示:

但是,我希望它出现在按钮下方的固定相对位置(假的,编辑的屏幕截图):

设置上下文菜单的Placement,PlacementRectangle和PlacementTarget性质似乎并没有做任何事情; 上下文菜单坚持在我右键单击我的按钮的任何地方悬挂光标.更糟糕的是,聚焦按钮并按下菜单键会使上下文菜单位于按钮前面,完全阻止它.
那么,我究竟如何指定上下文菜单应该出现在按钮下方?
Bal*_*a R 25
查看ContextMenu.Placement下的备注
试试这个
<Button Content="Do this" Height="23" Width="75"
ContextMenuService.Placement="Bottom"
Command="local:MyCommands.ThisCommand">
<Button.ContextMenu>
<ContextMenu>
<MenuItem Header="Do this" Command="local:MyCommands.ThisCommand" />
<MenuItem Header="Do that" Command="local:MyCommands.ThatCommand" />
</ContextMenu>
</Button.ContextMenu>
</Button>
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
8287 次 |
| 最近记录: |