{
// Create a menu and add commands specifying an id value for each instead of a delegate.
var menu = new PopupMenu();
menu.Commands.Add(new UICommand("Copy", null, 1));
menu.Commands.Add(new UICommandSeparator());
menu.Commands.Add(new UICommand("Highlight", null, 2));
menu.Commands.Add(new UICommand("Look up on dictionary", null, 3));
// We don't want to obscure content, so pass in a rectangle representing the sender of the context menu event.
// We registered command callbacks; no need to await and handle context menu completion
var chosenCommand = await menu.ShowForSelectionAsync(GetElementRect((FrameworkElement)sender));
if (chosenCommand != null)
{
switch ((int)chosenCommand.Id)
{
case 1:
Output2Text.Text = "'" + chosenCommand.Label + "'(" + chosenCommand.Id.ToString() + ") selected";
break;
case 2:
Output2Text.Text = "'" + chosenCommand.Label + "'(" + chosenCommand.Id.ToString() + ") selected";
break;
case 3:
Output2Text.Text = "'" + chosenCommand.Label + "'(" + chosenCommand.Id.ToString() + ") selected";
break;
}
}
else
{
Output2Text.Text = "Context menu dismissed";
}
}