【问题标题】:Pressing multiple buttons simultaneously同时按下多个按钮
【发布时间】:2012-07-02 10:16:16
【问题描述】:

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

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

【问题讨论】:

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


    【解决方案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”部分,您将检查 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.
    }
    

    希望对你有用。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-08-15
      • 2020-03-29
      • 1970-01-01
      • 2012-12-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多