c# - 同时按下多个按钮

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

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

我该如何克服这个问题?我需要能够允许用户同时按下多个按钮。

最佳答案

不幸的是,您无法同时处理多个按钮点击。虽然有一种解决方法。您可以使用 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
        }

    }
}

在“在这里做事”部分,您将检查 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.
}

希望这对您有用。

关于c# - 同时按下多个按钮,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11286229/

相关文章:

c# - 执行网络方法时出错

c# - 数据绑定(bind) Entity Framework 导航属性 - 处理更改

c# - 我们可以在 .aspx.cs 页面中编写单元测试方法吗?

c# - 恢复应用后,MediaElement无法播放

silverlight - 在 Windows Phone 应用程序中处理 SIP 的 Enter 键

c# - 动态增加数组中元素的数量

c# - 如何检测另一个音频是否在后台播放? ( window 电话 7)

windows-phone-7 - 非开发工具 Windows Phone 7 仿真

c# - 使用 Thread.sleep 让 UI 线程等待

windows-phone-7 - 如何处理 emailcomposetask 中的 "The size of input should not exceed 64K"异常?