After more exploration, there is no way to re-return to the Silverlight low-level touch event. However, gesturelistener is still reluctant to handle. After all, that operation is convenient. I can't help it now. I only need to write it myself. Just simulate it.
Now rewrite the previous live direction control disk.
First, complete the interface:
<Ellipse x:Name="innerRound" Width="100" Height="100" VerticalAlignment="Top" HorizontalAlignment="Left" Margin="100,350,0,0" Fill="Red" Stroke="Blue" StrokeThickness="5" > <Ellipse.RenderTransform> <TranslateTransform x:Name="innerTran"/> </Ellipse.RenderTransform> </Ellipse> <TextBlock x:Name="textblock1" Width="150" Height="80" HorizontalAlignment="Left" VerticalAlignment="Top" Text="click Me" FontSize="40" Margin="300,0,0,0"/> <TextBlock x:Name="direct" Text="direct" Width="200" Height="100" HorizontalAlignment="Left" VerticalAlignment="Top" FontSize="40" Margin="250,200,0,0"/> <TextBlock x:Name="click" Text="click" Width="150" Height="100" HorizontalAlignment="Left" VerticalAlignment="Top" FontSize="40" Margin="300,300,0,0"/>
Interface is not available. It is basically the same as the previous interface, that is, the color is not the same. Two textblocks are placed for multi-touch testing.
Then register the event in pageloaded:
Touch.FrameReported += new TouchFrameEventHandler(Touch_FrameReported);
But how can we simulate it? After all, this is a basic event. We get all the touch points, and the finger may not be placed in the disc when it is down for the first time. It may be moved in. All touchpoint Action events are hard to judge. Besides, I don't want to use two fingers to control my steering wheel. But how can I tell if the first finger has left the steering wheel. Action. Up? This is not the case. After all, it may be because you move it out.
In addition, to simulate gesturelistener, we mainly need to obtain the coordinate changes in both water and vertical directions. We can only record the previous coordinate first. To change the coordinates.
After careful consideration: the current rule is: Define a dictionary <int, point> to save touchdevice. ID and position of the previous vertex. Then we can use this to determine whether it is the original finger and get the coordinate change value. It also checks whether the action of a touchpoint is up. If it is up, determine whether it is the finger that just operated the disc. If yes, remove the finger from the dictionary, and then let the new finger in to operate the steering wheel.
Add two member variables:
Dictionary<int, Point> ETouchDict = new Dictionary<int, Point>(); TranslateTransform tr = new TranslateTransform();
The Code is as follows:
Void touch_framereported (Object sender, touchframeeventargs e) {touchpoint primarytouchpoint = E. getprimarytouchpoint (null); // inhibit mouse promotion if (primarytouchpoint! = NULL & primarytouchpoint. action = touchaction. down) E. suspendmousepromotionuntiltouchup (); touchpointcollection touchpoints = E. gettouchpoints (null); foreach (VAR item in touchpoints) {If (item. action = touchaction. up) {If (etouchdict. containskey (item. touchdevice. ID) {etouchdict. remove (item. touchdevice. ID); this. innertran. X = 0; this. innertran. y = 0; showdirect () ;}} if (item. touchdevice. Directlyover = textblock1) {// Debug. writeline ("textblock1 is touch! "+ Item. action. tostring (); click. TEXT = "A"; click. foreground = new solidcolorbrush (color. fromargb (255, (byte) Rand. next (256), (byte) Rand. next (256), (byte) Rand. next (256);} else if (item. touchdevice. directlyover = innerround) {// debug. writeline ("rectangle is touch! "+ Item. Action. tostring (); ellipsetouchhandle (item) ;}} void ellipsetouchhandle (touchpoint TP) {If (etouchdict. Count ()> 0 &&! Etouchdict. containskey (TP. touchdevice. ID) {return;} If (etouchdict. count () <= 0) {etouchdict. add (TP. touchdevice. ID, TP. position); // debug. writeline ("ellipse is touch! X: "+ TP. position. X + "Y:" + TP. position. y);} else {point lastpoint = etouchdict. firstordefault (). value; double horx = TP. position. x-lastpoint. x; double very = TP. position. y-lastpoint. y; Double X = This. innertran. X + horx; Double Y = This. innertran. Y + very; If (x <=-50) This. innertran. X =-50; else if (x> = 50) This. innertran. X = 50; else this. innertran. X = x; If (Y <=-50) This. innertran. Y =-50; else if (Y> = 50) This. innertran. y = 50; else this. innertran. y = y; showdirect (); // debug. writeline ("ellipse is touch! Horizontalvelocity (x): "+ horx. tostring () + "verticalvelocity (y):" + very. tostring (); etouchdict. remove (TP. touchdevice. ID); etouchdict. add (TP. touchdevice. ID, TP. position) ;}} void showdirect () {Double X = innertran. x; Double Y = innertran. y; If (x <=-15 & x> =-50 & Y <=-15 & Y> =-50) {direct. TEXT = "upper left" + x + "," + Y ;} else if (x> = 15 & x <= 50 & Y <=-15 & Y> =-50) {direct. TEXT = "upper right" + x + "," + Y ;} else if (x <=-15 & x> =-50 & Y> = 15 & Y <= 50) {direct. TEXT = "bottom left" + x + "," + Y ;} else if (x> = 15 & x <= 50 & Y> = 15 & Y <= 50) {direct. TEXT = "lower right" + x + "," + Y;} else if (x <= 15 & x> =-15 & Y <0) {direct. TEXT = "up" + x + "," + Y;} else if (x <= 15 & x> =-15 & Y> 0) {direct. TEXT = "lower" + x + "," + Y;} else if (Y <= 15 & Y> =-15 & x <0) {direct. TEXT = "Left" + x + "," + Y;} else if (Y <= 15 & Y> =-15 & x> 0) {direct. TEXT = "right" + x + "," + Y;} else {direct. TEXT = "";}}
In this way, you can use multi-touch. In addition, no matter how you operate, my steering wheel and the so-called a key can issue a "command.
The result is really bad. After all, it was debugged on a real machine. Put the project on. Http://115.com/file/c2p3tv39#MultiTouchDemo.zip