问题描述
<ContextMenu x:Key="CMexe" x:Name="CM_exe" Background="#f2f2f2" Width="220">
<MenuItem x:Name="l4" Margin="0 1 0 1" Header="Send To">
<MenuItem x:Name="l41" Margin="0 1 0 1" FontWeight="Bold" Header="Orignal Desktop" />
<MenuItem x:Name="l42" Margin="0 1 0 1" FontWeight="Bold" Header="Orignal Desktop (Shortcut)" />
<MenuItem x:Name="l43" Margin="0 1 0 1" FontWeight="Bold" Header="Documents" />
<MenuItem x:Name="l44" Margin="0 1 0 1" FontWeight="Bold" Header="Downloads" />
</MenuItem>
</ContextMenu>
:
项目l41,l42,l43, l44应该显示为子菜单,但它们不是。
the items l41,l42,l43,l44 should appear as a submenu, but they are not.
推荐答案
上下文菜单(通常称为弹出菜单或弹出菜单)是在某些用户操作时显示的菜单,通常是用鼠标右键单击特定控件或窗口。
A context menu, often referred to as a popup or pop-up menu, is a menu which is shown upon certain user actions, usually a right-click with the mouse on a specific control or window.
ContextMenu附加到特定控件。 ContextMenu元素使您能够向用户显示指定与特定控件关联的命令或选项的项目列表,例如Button。用户右键单击控件
以显示菜单。通常,单击MenuItem会打开子菜单或导致应用程序执行命令。
A ContextMenu is attached to a specific control. The ContextMenu element enables you to present users with a list of items that specify commands or options that are associated with a particular control, for example, a Button. Users right-click the control to make the menu appear. Typically, clicking a MenuItem opens a submenu or causes an application to carry out a command.
<Window.Resources>
<ContextMenu
x:Key="CMexe"
x:Name="CM_exe"
Width="220"
Background="#f2f2f2">
<MenuItem
x:Name="l4"
Margin="0,1,0,1"
Header="Send To">
<MenuItem
x:Name="l41"
Margin="0,1,0,1"
FontWeight="Bold"
Header="Orignal Desktop" />
<MenuItem
x:Name="l42"
Margin="0,1,0,1"
FontWeight="Bold"
Header="Orignal Desktop (Shortcut)" />
<MenuItem
x:Name="l43"
Margin="0,1,0,1"
FontWeight="Bold"
Header="Documents" />
<MenuItem
x:Name="l44"
Margin="0,1,0,1"
FontWeight="Bold"
Header="Downloads" />
</MenuItem>
</ContextMenu>
</Window.Resources>
<Grid>
<Button
Name="btn1"
Width="200"
Height="30"
Content="btn1"
ContextMenu="{StaticResource CMexe}" />
</Grid>
这是关于Contextmenu的,你可以看看:
Here is about Contextmenu, you can take a look:
https://www.wpf-tutorial.com/common-interface-controls/contextmenu/
最好的问候,
Cherry
这篇关于wpf ContextMenu的Sub MenuItems未显示/出现的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!