How to check if 3 fingers are placed on the screen

2019-05-02 06:48发布

问题:

For my application I'd like to use all the built in manipulation possibilities, like e.g. zoom. But if the user presses 3 fingers on the screen I'd like to show a specific UI element. So what is the best way to check if the user has pressed 3 fingers at the same time and next to each other on the screen? (without disabling the built-in manipulation possibilties).

My first approach was to register the TouchDown event on the top Grid element of my layout. In the event handler I get the contact. But what to do there?

Just check if the contact is a fingerprint, store it in a List, and check if the list already contains two similar conacts?

Or is there a more sexy solution?

Thanks!

Edit:

Following the answer i wrote two methods:

private void OnContactDown(object sender, ContactEventArgs e)
        {
            if (this.ContactsOver.Count == 3)
            {
                Console.WriteLine("3 contacts down. Check proximity");

                if (areNear(this.ContactsOver))
                {
                    Console.WriteLine("3 fingers down!");
                }
            }
        }

        private Boolean areNear(ReadOnlyContactCollection contacts)
        {
            if ( Math.Abs(contacts.ElementAt(0).GetCenterPosition(this).X - contacts.ElementAt(1).GetCenterPosition(this).X) < 100 &&
                 Math.Abs(contacts.ElementAt(0).GetCenterPosition(this).Y - contacts.ElementAt(1).GetCenterPosition(this).Y) < 100 &&
                 Math.Abs(contacts.ElementAt(1).GetCenterPosition(this).X - contacts.ElementAt(2).GetCenterPosition(this).X) < 100 &&
                 Math.Abs(contacts.ElementAt(1).GetCenterPosition(this).Y - contacts.ElementAt(2).GetCenterPosition(this).Y) < 100 &&
                 Math.Abs(contacts.ElementAt(0).GetCenterPosition(this).X - contacts.ElementAt(2).GetCenterPosition(this).X) < 100 &&
                 Math.Abs(contacts.ElementAt(0).GetCenterPosition(this).Y - contacts.ElementAt(2).GetCenterPosition(this).Y) < 100)
            {
                return true;
            }
            else
            {
                return false;
            }
        }

They have to be rewritten, but it works. And the threshold (atm 100) has to be adjusted.

回答1:

There is a property on all surface controls that contains the number of contacts över it. The propery is ContactsOver or any variant of it depending on your need, see http://msdn.microsoft.com/en-us/library/microsoft.surface.presentation.controls.surfacecontrol_properties(v=Surface.10).aspx

You could check that propery's Count value in your ContactDown event handler for instance. To check their distance, just do a GetPosition on them and use basic vector math on the points.