在我的 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/