同时按下多个按钮

时间:2012-07-01 22:52:38

标签: c# windows-phone-7 windows-phone-7.1 multi-touch

在我的WP 7.1应用程序中,我有一个带有多个按钮的页面 我注意到,当按下任何一个按钮时,不能按任何其他按钮。

我怎样才能克服这一点?我需要能够允许用户同时按下多个按钮。

1 个答案:

答案 0 :(得分:4)

不幸的是,您无法一次处理多个按钮点击。虽然有一种解决方法。您可以使用Touch.FrameReported事件来获取用户在屏幕上触摸的所有点的位置(我在WP7之前的某处读过它仅限于两个,但我无法验证)。您还可以检查用户正在执行的操作(例如,向下,向上和向上),这可能会有用,具体取决于您正在执行的操作。

将其放入Application_Startup

Touch.FrameReported += new TouchFrameEventHandler(Touch_FrameReported);

将其放入App类

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
        }

    }
}

在“Do stuff here”部分中,您将检查TouchPoint tp是否位于按钮占用的区域内。

//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.
}

希望能为你做到这一点。