Next, add a rectangle dynamically in the previous section. In practical application, we dynamically Add a rectangle box, right-click the rectangle box, get a pop-up window, and then associate some actual information with the rectangle box. You can customize the configuration page. This section describes two tips: 1. Right-click the menu. Ii. Silverlight full screen mode.
1. Right-click the menu. Here we need to introduce two DLL files separately. (Right-click the project name --> "add reference" --> Find system. Windows. Controls. Input. toolkit. dll [You can referSource codeFind])
System. Windows. controls;
System. Windows. Controls. Input. toolkit;
Mainpage. XAMLCodeAs follows:
<Usercontrol X: class = "slrightmousebutton. mainpage "xmlns: My =" CLR-namespace: system. windows. controls; Assembly = system. windows. controls. input. toolkit "xmlns =" http://schemas.microsoft.com/winfx/2006/xaml/presentation "xmlns: x =" http://schemas.microsoft.com/winfx/2006/xaml "width =" 640 "Height =" 480 "> <canvas X: Name =" layoutroot "> <rectangle X: name = "ti" width = "150" Height = "150" radiusx = "5" radiusy = "5" fill = "blue"> </rectangle> <my: contextmenuservice. contextmenu> <my: contextmenu name = "mymenu"> <my: menuitem header = "associated region" Click = "menuitem_click"/> <my: separator/> <my: menuitem header = "associated page" Click = "menuitem_click"/> <my: separator/> <my: menuitem header = "entering full screen" Click = "menuitem_click"/> </My: contextmenu> </My: contextmenuservice. contextmenu> </canvas> </usercontrol>
Here it is obvious that you can right-click the rectangle area named Ti, and right-click to get three items from the context menu: "association region" association page "and" entering full screen. All three items are added to the same Click Event menuitem_click for processing.
The key code for processing the menuitem_click event in the mainpage. XAML. CS file is as follows:
/// <Summary> /// right-click to select the event of the corresponding item /// </Summary> /// <Param name = "sender"> </param>/ // <Param name = "E"> </param> private void menuitem_click (Object sender, routedeventargs e) {menuitem = (menuitem) sender; Switch (menuitem. header. tostring () {Case "associated region": MessageBox. show ("associated region"); // A subwindow of the associated region is displayed. Then select the corresponding data. For this reason, the rectangle is associated with the regional break; Case "associated page": MessageBox. show ("Join page"); // A subwindow of the join page is displayed. Then select the corresponding data. For this reason, rectangle is associated with the page break; Case "to enter full screen": menuitem. header = fullscreens (menuitem. header. tostring (); // call the fullscreens function to set whether the current screen is full or not, and obtain the right-click menu header obtained by right-clicking next time. Break; Case "cancel full screen": menuitem. header = fullscreens (menuitem. header. tostring (); break; default: break;} mymenu. isopen = false; // right-click the menu to close} /// <summary> /// whether to enter full screen // </Summary> /// <Param name = "isscreen"> full screen parameters </ param> // <returns> </returns> private string fullscreens (string isscreen) {application. current. host. content. isfullscreen =! Application. current. host. content. isfullscreen; If (isscreen = "") {isscreen = "";} else {isscreen = "";} return isscreen ;}}
Use menuitem = (menuitem) sender in the Code; capture the object that triggers this event, and then determine the value of the header of the current object? Then proceed with the corresponding processing. It is worth noting that this involves the second small knowledge point we need today.
2. Enter the full screen mode of Silverlight.
Application. Current. Host. content. isfullscreen =! Application. Current. Host. content. isfullscreen;
This simple code will allow your SilverlightProgramEnter or exit full screen mode.
The source code of this instance is developed based on Silverlight 4.0 and vs 2010.
The source code of this section is attached with click http://files.cnblogs.com/chengxingliang/SLRightMouseButton.rar
To download the required DLL, click system.windows.controls.data.input.rar.