我想在对话框中创建一个上下文菜单,并尝试从List View控件中使用此事件ContextMenuCreated。所以我创建了上下文菜单,但我想知道如何将方法委托给我创建的那些菜单项。这是代码:
dialogFilter.RegisterForContextMenu(listView);
listView.ContextMenuCreated += delegate(object sender, CreateContextMenuEventArgs e) {
e.Menu.SetHeaderTitle("Options");
e.Menu.Add(0,1,1,"Edit");
e.Menu.Add(0,2,1,"Delete");
};
答案 0 :(得分:1)
也许这就是你要找的东西:
public override void OnCreateContextMenu(IContextMenu menu, View v, ContextMenuContextMenuInfo menuInfo)
{
base.OnCreateContextMenu(menu, v, menuInfo);
menu.SetHeaderTitle("Options");
menu.Add(0,1,1,"Edit");
menu.Add(0,2,1,"Delete");
}
public override bool OnContextItemSelected(IMenuItem item)
{
Toast.MakeText(this, item.TitleFormatted, ToastLength.Short).Show();
return true;
}
希望有所帮助。