Usage of contextmenu in Silverlight Toolkit

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.