在我的 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
}
}
}
在“Do stuff here”部分中,您将检查触摸点是否位于按钮占据的区域内。
//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.
}
希望这对你有用。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)