Contextmenu, which can be considered as a context menu, appears on a control on time.
For example:
It can be used in two ways.
First, use the code to implement the contextmenuservice
Contextmenu menu = new contextmenu ();
Menuitem menuitem1 = new menuitem ();
Menuitem1.header = "this is menu item 1 ";
Menuitem1.click + = new routedeventhandler (menuitem_click );
Menu. Items. Add (menuitem1 );
Menuitem menuitem2 = new menuitem ();
Menuitem2.header = "this is menu item 2 ";
Menuitem2.click + = new routedeventhandler (menuitem_click );
Menu. Items. Add (menuitem2 );
Contextmenuservice. setcontextmenu (RC, menu); // The RC here indicates the name of the rectangle box, or the name of the Control attached to the contextmenu.
Second, by modifying the XAML File
First, you need to add the namespace: xmlns: Toolkit = "CLR-namespace: Microsoft. Phone. controls; Assembly = Microsoft. Phone. Controls. toolkit"
Next, add the following content:
<Rectangle width = "100" Height = "100" fill = "red">
<Toolkit: contextmenuservice. contextmenu>
<Toolkit: contextmenu>
<Toolkit: menuitem header = "this is menu item 1" Click = "menuitem_click"/>
<Toolkit: menuitem header = "this is menu item 2" Click = "menuitem_click"/>
<Toolkit: menuitem header = "this is menu item 3" Click = "menuitem_click"/>
</Toolkit: contextmenu>
</Toolkit: contextmenuservice. contextmenu>
</Rectangle>
Actual results:
In addition, when using contextmenu, you will notice the zoom in and out of the background content on the simulator. This can be controlled through the iszoomenabled attribute. When it is set to false, the auto scaling animation can be stopped.
<Toolkit: contextmenu iszoomenabled = "false"> -------------- THIS is what we talked about on the 21st.
The result of an attempt on the simulator is that the setting of this attribute does not take effect. I don't know why.
Update:
The iszoomenabled attribute works on the button control. When you add a contextmenu on a button, set iszoomenabled to false. In this case, the background has no auto scaling effect.
A more detailed article about contextmenu:
Http://www.windowsphonegeek.com/articles/WP7-ContextMenu-in-depth--Part1-key-concepts-and-API