The implementation of double-click and multiple-click is added in Silverlight 5, including the left-click and right-click double-click, multiple-click. In the mousebuttoneventargs class of Silverlight 5, a property named clickcount is added: the trigger event source is obtained inUnit timeNumber of inner clicks (note:Unit timeIs set by the "control panel" --> "Mouse" --> "double-click speed" of the operating system ).
Next, let's look at an instance to determine whether to double-click or multi-click it. First, let's look at the instance's XAMLCode:
< Grid X: Name = " Layoutroot " Background = " White " >
< Ellipse height = " 103 " Horizontalalignment = " Left " Fill = " Green " Margin = " 117,56, 0, 0 "
Name = " Ellipse1 " Stroke = " Black " Strokethickness = " 1 " Verticalalignment = " Top "
Width = " 158 " Mouseleftbuttondown = " Ellipse1_mouseleftbuttondown "
Mouserightbuttondown = " Ellipse2_mouserightbuttondown " />
</ Grid >
1. Let's take a look at double-clicking the left mouse button (similar to triple-clicking). The judgment is as follows:
Private Void Ellipse1_mouseleftbuttondown ( Object Sender, mousebuttoneventargs E)
{
// Determines that the mouse is clicked twice within the double-click interval set by the system. The window is displayed.
If (E. clickcount = 2 )
{
MessageBox. Show ( " Left mouse click " + E. clickcount. tostring ());
}
}
When you double-click the left mouse button, the result is as follows:
2. In some cases, we need to determine whether to double-click or triple-click the right mouse. In this case, just enter the following code:
Private Void Ellipse2_mouserightbuttondown ( Object Sender, mousebuttoneventargs E)
{
// Right-click and choose 3.
If (E. clickcount = 3 )
{
MessageBox. Show ( " Right-click " + E. clickcount. tostring () + " Times! " );
}
}
However, when we run it, we find that the slice effect is shown, but it cannot be right-clicked:
By default, Microsoft has a right-click menu. You need to disable this default right-click menu to enable multiple clicks.
A. On the sl5doubleclicktestpage. ASPX page, change the <body> element to <body oncontextmenu = "window. event. returnvalue = false">.
B. Add a line in the <Object> label <Param name = "windowless" value = "true"/> to disable the default right-click menu.
The effect of right-click and three-click operations is as follows:
This example is written in vs2010 + Silverlight 5 beta. To download the source code, click sl5doubleclick.zip.