English 中文(简体)
如何在 WPF 中以特定位置添加菜单项?
原标题:How to add menu items in specific position in WPF?
  • 时间:2012-05-27 14:34:26
  •  标签:
  • c#
  • wpf

我想添加这样的菜单项 :

AddChild(new MenuItem
{
    Header = "Test"
});

然而,问题在于菜单项出现在结尾处(逻辑上), 现在我正在寻找一种方法, 把它添加到特定的位置上 。

--A--
--B--
--C--

我想在A和B之间加上它。 XAML就像:

<ContextMenu>
    <MenuItem ... />
    <MenuItem ... />
    <MenuItem ... />
</ContextMenu>

代码在上下文菜单的上下文中运行。我可以访问现有菜单项目的名称A ,例如它们的名称A

最佳回答

尝试

myContextMenu.Items.Insert( newIndex, new MenuItem() {Header="Test"});
问题回答

暂无回答




相关问题
Anyone feel like passing it forward?

I m the only developer in my company, and am getting along well as an autodidact, but I know I m missing out on the education one gets from working with and having code reviewed by more senior devs. ...

NSArray s, Primitive types and Boxing Oh My!

I m pretty new to the Objective-C world and I have a long history with .net/C# so naturally I m inclined to use my C# wits. Now here s the question: I feel really inclined to create some type of ...

C# Marshal / Pinvoke CBitmap?

I cannot figure out how to marshal a C++ CBitmap to a C# Bitmap or Image class. My import looks like this: [DllImport(@"test.dll", CharSet = CharSet.Unicode)] public static extern IntPtr ...

How to Use Ghostscript DLL to convert PDF to PDF/A

How to user GhostScript DLL to convert PDF to PDF/A. I know I kind of have to call the exported function of gsdll32.dll whose name is gsapi_init_with_args, but how do i pass the right arguments? BTW, ...

Linqy no matchy

Maybe it s something I m doing wrong. I m just learning Linq because I m bored. And so far so good. I made a little program and it basically just outputs all matches (foreach) into a label control. ...

热门标签