Metro Nuggets

Bitesized tidbits for building Modern (Metro) apps.

Category Archives: WPToolkit

Launching a Context Menu From Code

One of the great things the Windows Phone Toolkit brings developers is the ContextMenu and ContextMenuService that allows developers to offer their users a tap and hold menu, the same kind that appears in the OS itself.

Generally, you would create the context menu in xaml and attach it to an item within your page (or DataTemplate), but what if you want the user to be able to tap a button and have it appear? If you create the ContextMenu as normal in xaml then try and launch it from code, you’ll end up with an exception being through that the Element is already a child of another element. But if you create it in code, then it might not appear where you want it to appear, so what then?

Read more of this post