I want to add a menu item like this:
AddChild(new MenuItem
{
Header = "Test"
});
However, the problem with that is that the menu item appears in the end (logically), now I'm looking for a way to add it to a specific position.
--A--
--B--
--C--
I want to add it between A and B. The XAML is like:
<ContextMenu>
<MenuItem ... />
<MenuItem ... />
<MenuItem ... />
</ContextMenu>
The code runs in context of the context menu. And I can access the existing menu items by their name A, for example.
Try
myContextMenu.Items.Insert( newIndex, new MenuItem() {Header="Test"});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With