Everyday problems and solutions living the life of an adventurous developer at the intersection of .NET and IOS.

30 January, 2013

WPF MenuItem programmatically

I seriously don’t know what they had been smoking in Redmond when they invented the URI scheme for WPF. It’s really far from intuitive nor understandable, so if you have set out to create e.g. a ContextMenu programmatically (code over Markup XAML); you are in for a surprise!

Building an editor that required a dynamic tabcontrol (you can add/delete the tabs during runtime); I had to enable a contextmenu associated to these new runtime defined tab items. But, creating these menuitems in code (C#) is not intuitive. So, if you don’t want to spend 1½ hour hunting how to do this, here is how: