Windows 10 Development Diary (iii)--How to determine the number of fingers before the gesture starts

Source: Internet
Author: User

This is a problem that we often face in real-world projects, because you are likely to have this requirement: one-hand operation is different from the action of the hands, and you need to know whether one hand or both hands are at the beginning of the gesture.

programme One:

Having understood this requirement, I quickly experienced the feeling that the arguments passed in the manipulationstarting or manipulationstarted event should resemble the E.getpointers () similar method, Used to get the number of fingers currently on the screen. Feel three years of experience in Windows development finally has a little use, save me a lot of efficiency inevitably have a hunch ... But when looking for a half-day, the chest immediately after tens of thousands of grass mud horse Pentium, not that is the bottom of the event? Bottom-level event even the simplest judgment, how many fingers do you have? Touchframe is called the bottom-level event, okay???

    public class Manipulationstartedroutedeventargs:routedeventargs, Imanipulationstartedroutedeventargs    {        public Manipulationstartedroutedeventargs ();        Public UIElement Container {get;}        Public Manipulationdelta cumulative {get;}        Public System.Boolean Handled {get; set;}        Public Pointerdevicetype Pointerdevicetype {get;}        Public point Position {get;}        public void complete ();    

Please see, I will not wronged the good people, there is not a set of things, this point is the finger on the screen touch points, but this is the started event, okay? I want to know how many fingers are in contact with the screen before started, okay?

Scenario Two:

Holding "Microsoft Abuse me times, I am waiting for Microsoft like first love" mentality, I continue to look for program two. Thought: If I can get this container, even if I get the app's frame, there should be an exposure method to determine how many fingers. The concrete process I will not say, God horse uielement,control,frame, have no ah, have no.

Programme III:

Holding "people under the eaves, have to bow" mentality, I continue to look for three, (after all, the technology is your Microsoft, the project is mine, still have to continue ah, 10,000 grass mud horse and whistling again ...) ), to the MSDN above the grilled with the input related knowledge points, and finally found a thing, and is a more familiar thing: pointerpressed, intermediate events, this event we have done an experiment, it will be triggered before manipulationstarting, That is, if I can get the number of fingers when this event triggers, then I can solve the problem! (https://msdn.microsoft.com/en-us/library/windows/apps/xaml/jj150606.aspx, this article details pointer related knowledge, interested friends can go to see, Grass mud Horse All disappeared, the future is bright ah, haha ha)

It can be said that every click will trigger a pointerpressed event, and the parameters of this event can get contact information, this information contains the Pointerid, that is, every click, the system will identify the contact point, released after the system to reclaim the mark, Then we can implement a local dictionary, to Pointerid as key, the corresponding pointer is value, then in the Onmanipulationstarting event I can judge is a few fingers, say dry do

        Private Dictionary<uint, point?> _contacts; A collection of points that touch the screen///<summary>///finger press///</summary>//<param name= "E" ></ param> protected override void Onpointerpressed (Pointerroutedeventargs e) {//if (E.pointer.po Interdevicetype! = Windows.Devices.Input.PointerDeviceType.Mouse)//{_contacts[e.pointer.pointe RId] = E.getcurrentpoint (this).            Position;        } e.handled = true;        }///<summary>//finger leave//</summary>//<param name= "E" ></param> protected override void Onpointerreleased (Pointerroutedeventargs e) {//if (E.pointer.pointerdevic EType! = Windows.Devices.Input.PointerDeviceType.Mouse)//{if (_contacts.                    ContainsKey (E.pointer.pointerid)) {_contacts[e.pointer.pointerid] = null; _contacts. ReMove (E.pointer.pointerid);        }//} e.handled = true; }///<summary>//The finger will only start starting event, to move before starting to trigger started events///</summary>//&LT;PA        Ram Name= "E" ></param> protected override void Onmanipulationstarted (Manipulationstartedroutedeventargs e) {int count = _contacts.            Count;            if (count = = 1) {//If at this point there is only one finger, it is considered in the contrast mode _viewcontroller.onmanipulationstarted (e);            } else if (Count > 1) {//If the finger is more than one, it is considered e.handled = true in zoom mode; }        }

Wow haha, at this time, the function is done, it is time to look back, why manipulationstarting can not provide getpoints () method. From the experimental results, manipulationstarting should be only for a single operation to say, or, manipulationstarting is just a "preparation" of the action, and can not do a lot of things. But Manipulationdelta can also judge the operation of the two hands: scale, the amount, this will be in the future slowly pondering.

This article should help you if you also have a situation where you can judge your finger before you do it.

This is the part of the gesture, because I have only encountered these problems in my project, and I do not rule out that there are more complications in the follow-up, or that many other problems have been extended.

Windows 10 Development Diary (iii)--How to determine the number of fingers before the gesture starts

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.