sternr
sternr

Reputation: 6536

Pressing multiple buttons simultaneously

In my WP 7.1 app I have a page with multiple buttons.
I noticed that while any one button is being pressed, no other button can be pressed.

How can I overcome this? I need to be able to allow users to press multiple buttons at the same time.

Upvotes: 6

Views: 3293

Answers (1)

Darcon
Darcon

Reputation: 219

You can't handle multiple button clicks at once unfortunately. There is a way around it though. You can use the Touch.FrameReported event to get the position of all the points a user is touching on the screen (I read somewhere before that on WP7 it's limited to two but I can't verify that). You can also check if the action the user is taking (e.g. Down, Move and Up) which may be useful depending on what you are doing.

Put this in your Application_Startup

Touch.FrameReported += new TouchFrameEventHandler(Touch_FrameReported);

Put this in your App class

void Touch_FrameReported(object sender, TouchFrameEventArgs e)
{
    TouchPoint primaryTouchPoint = args.GetPrimaryTouchPoint(null);


    TouchPointCollection touchPoints = args.GetTouchPoints(null);


    foreach (TouchPoint tp in touchPoints)
    {
        if(tp.Action == TouchAction.Down)
        {
        //Do stuff here
        }

    }
}

In the "Do stuff here" part you would check if the TouchPoint tp is within an area a button occupies.

//This is the rectangle where your button is located, change values as needed.
Rectangle r1 = new Rectangle(0, 0, 100, 100); 
if (r1.Contains(tp.Position))
{
   //Do button click stuff here.
}

That should hopefully do it for you.

Upvotes: 4

Related Questions