Context Menu example this example shows how to create a context menu and how to replace the default context menu text. This example uses Windows. UI. The popupmenu and oncontextmenu events are displayed. This example demonstrates the two tasks: • create a context menu to display as a file • Replace the default command with the text displayed in the context menu to understand the selection command and design a context menu, see the context menu of the Guidelines and checklists. Additional APIs for this example include: • uicommand class • uicommandseparator class async Void Scenario2textbox_contextmenuopening ( Object Sender, contextmenueventargs E)
{
// 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 " ;
}
}
Complete example:/files/risk/windows8/upload/download ticket sample.rar