我想要实现以下目标:
<Style TargetType="ListBoxItem">
<Setter Property="ContextMenu">
<Setter.Value>
<ContextMenu>
<MenuItem Name="mnuEdit" Header="_Edit" Click="MenuItem_Click" />
</ContextMenu>
</Setter.Value>
</Setter>
<Style>
Run Code Online (Sandbox Code Playgroud)
但它抛出以下异常:
Cannot add content of type 'System.Windows.Controls.ContextMenu'
to an object of type 'System.Object'.
Error at object 'System.Windows.Controls.ContextMenu'
in markup file blah blah blah
Run Code Online (Sandbox Code Playgroud) 我有一个带有项目的ListBox,并为其分配了一个ContextMenu,其中包含三个菜单项.除了其中一个菜单项启动冗长的操作外,一切正常.我想从处理程序关闭ContextMenu,并可能显示一个沙漏光标或其他东西.
可以这样做吗?或者,我应该使用Popup吗?如果是这样,我如何使用Popup代替ContextMenu?我的假设是我必须完全管理它 - 安置和生命.
谢谢!
我有一个基于系统托盘的应用程序.如果你右键单击它我有一个很好的上下文菜单但是我想要一个不同的上下文菜单,如果你点击它就会出现.现在我把不同的菜单显示出来
private void niTrayIcon_MouseClick(object sender, MouseEventArgs e)
{
if (e.Button == System.Windows.Forms.MouseButtons.Left)
{
cmsTrayLeftClick.Show(Cursor.Position);
}
}
Run Code Online (Sandbox Code Playgroud)
这使得菜单显示但单击菜单不会使其消失,使菜单消失的唯一方法是单击项目或rt单击托盘图标.
我也想出了这个黑客,但它确实感觉这是正确的方法.
private void niTrayIcon_MouseClick(object sender, MouseEventArgs e)
{
if (e.Button == System.Windows.Forms.MouseButtons.Left)
{
niTrayIcon.ContextMenuStrip = cmsTrayLeftClick;
MethodInfo mi = typeof(NotifyIcon).GetMethod("ShowContextMenu", BindingFlags.Instance | BindingFlags.NonPublic);
mi.Invoke(niTrayIcon, null);
niTrayIcon.ContextMenuStrip = cmsTrayRtClick;
}
}
Run Code Online (Sandbox Code Playgroud)
这是正确的做法还是有更优雅的方式?
我在Eclipse 3.5.2(Ubuntu 10.10)安装中安装了几个插件(Apatana,SVN,Pydev,Zend Debugger,PHP).自从我多年前第一次使用Eclipse以来一直困扰着我的一个问题是,每个插件都会将新条目放入上下文菜单中.
不幸的是,似乎各种观点无法确定哪些菜单条目无用.因此,在编程PHP时,菜单中充满了java和pydev的东西,我真的没用!
安装的插件越多,菜单越混乱.看起来有点奇怪,这样一个丰富的IDE不支持上下文敏感的"上下文"菜单...... :-(
我的希望是,在互联网上的某个地方,有人知道如何删除未使用的菜单条目,甚至为此创建了一个小插件?
有任何想法吗?
我通过以下方式动态地将字符串(项)添加到ToolStripItemCollection:
Dim onClickHandler As System.EventHandler = New System.EventHandler(AddressOf Symbol_Click)
Dim item As New ToolStripMenuItem(newSymbol, Nothing, onClickHandler)
SomeToolStripMenuItem.DropDownItems.Add(item)
Run Code Online (Sandbox Code Playgroud)
因此,这些项目不会一次性添加,而是在整个程序会话中基于外部触发器逐个添加.我想在每次添加新项目时对下拉列表进行排序.我有什么选择来实现这一目标?
是否可以在特定索引处将ToolStripMenuItems添加到ContextMenuStrip?我有一个项目列表,我想将它们添加到ContextMenuStrip,我想知道是否可以在特定索引处将项目添加到ContextMenu.
这是我的清单:
Item1
Item2
Item3
Item4
Run Code Online (Sandbox Code Playgroud)
我想将它们添加到ContextMenu中,因此它们在菜单中显示如下:
Item2
Item3
Item1
Item4
Run Code Online (Sandbox Code Playgroud)
有可能吗?
非常感谢所有帮助.
我正在尝试在右键单击项目时将上下文菜单添加到列表框中.
我甚至不确定右键单击功能是否正常工作.
这是代码:
private void lstSource_MouseDown(object sender, MouseEventArgs e)
{
if (e.Button == MouseButtons.Right)
{
Console.WriteLine("Right Click");
}
}
Run Code Online (Sandbox Code Playgroud)
没有任何东西打印到控制台.我错过了什么吗?
谢谢.
所以我的ExpandableListView组行定义如下:
group_row.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<TextView
android:id="@+id/GroupName"
style="@style/ListViewRowStyle"
android:paddingLeft="40dp"
android:textSize="18sp" >
</TextView>
<ImageView
android:id="@+id/Menu"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_marginTop="10dp"
android:contentDescription="@string/default_content_description_text"
android:src="@drawable/ic_menu_moreoverflow_normal_holo_light" >
</ImageView>
</RelativeLayout>
Run Code Online (Sandbox Code Playgroud)
当您单击TextView它时,它将展开或折叠,具体取决于当前是否显示子行.我附上了OnClickListener该ImageView组一行.ImageView单击此按钮时,我会启动PopupMenu如下图像:


一旦PopupMenu显示和动作中的一个被点击,我想在该组的所有儿童执行操作.问题是我无法确定ImageView单击的行.
我弄清楚如何将动作应用于所有孩子的唯一方法是使用ContextMenu如下图像:

我想避免使用a,ContextMenu因为组行上的LongClick可能不明显,用户无法确定它会在子行上执行某些操作.我认为更明显的设计是将a锚定PopupMenu到ImageView(在我的情况下是菜单图标)并将操作应用于该组的子行.我怎样才能获得这个功能PopupMenu?
android contextmenu popupmenu expandablelistview onclicklistener
我在我的NSTextField中单击鼠标右键显示一个上下文菜单。我正在使用以下代码在NSTextField的rightMouseDown事件中弹出上下文菜单:
- (void) rightMouseDown:(NSEvent*)theEvent
{
NSMenu* theMenu = [[NSMenu alloc] initWithTitle:@"Contextual Menu"];
[theMenu insertItemWithTitle:@"Suggest Link/Movie" action:@selector(openSuggestionMovieLink) keyEquivalent:@"" atIndex:0];
[theMenu setDelegate:self];
[NSMenu popUpContextMenu:theMenu withEvent:theEvent forView:self];
}
Run Code Online (Sandbox Code Playgroud)
当用户单击窗口中的任意位置时,我需要停止关闭此上下文菜单。
我尝试通过覆盖窗口的mouse down事件并在上下文菜单打开时不发送[super mousedown:event]调用来完成此操作。这没有用。
我也尝试使用NSMenu委托方法menuDidClose:并再次打开其中的菜单。
- (void)menuDidClose:(NSMenu *)menu
{
NSLog(@"close");
[NSMenu popUpContextMenu:menu withEvent:nil forView:self];
}
Run Code Online (Sandbox Code Playgroud)
但是没有任何东西对我有用。
有什么办法可以做到这一点。请指出正确的方向。我将不胜感激。谢谢。
我正在从ContextMenu启动外部应用程序,我必须在目标应用程序运行时阻止源应用程序.为实现这一点,我Process.WaitForExit()用来避免源应用程序响应事件.
问题是上下文菜单仍然领先于目标应用程序.让我们看一个简单的例子:
这是我用于示例的代码.
public MainWindow()
{
InitializeComponent();
this.ContextMenu = new ContextMenu();
MenuItem menuItem1 = new MenuItem();
menuItem1.Header = "Launch notepad";
menuItem1.Click += MyMenuItem_Click;
this.ContextMenu.Items.Add(menuItem1);
}
void MyMenuItem_Click(object sender, RoutedEventArgs e)
{
Process p = new Process();
p.StartInfo.FileName = "notepad.exe";
p.StartInfo.CreateNoWindow = false;
p.Start();
p.WaitForExit();
p.Close();
}
Run Code Online (Sandbox Code Playgroud)
如何在显示目标应用程序之前使ContextMenu消失?
contextmenu ×10
c# ×5
winforms ×3
wpf ×3
.net ×2
android ×1
cocoa ×1
eclipse ×1
listbox ×1
listboxitem ×1
macos ×1
notifyicon ×1
objective-c ×1
plugins ×1
popup ×1
popupmenu ×1
right-click ×1
setter ×1
styles ×1
vb.net ×1
xaml ×1