Pressing multiple buttons simultaneously

走远了吗. 提交于 2019-12-18 12:36:11

问题


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.


回答1:


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.



来源:https://stackoverflow.com/questions/11286229/pressing-multiple-buttons-simultaneously

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!