【问题标题】:Why are Stylus and Mouse events fired when touching my object?为什么触摸我的对象时会触发 Stylus 和 Mouse 事件?
【发布时间】:2015-05-07 14:02:40
【问题描述】:

我有一个PushPin 对象,我已经连接了一些触摸/触控笔/鼠标事件:

pp.MouseDown += pp_MouseDown;
pp.TouchDown += pp_TouchDown;
pp.TouchUp += pp_TouchUp;
pp.StylusDown += pp_StylusDown;
pp.StylusUp += pp_StylusUp;

处理程序

    void pp_MouseDown(object sender, MouseButtonEventArgs e)
    {
        PushPinUpOrDown(sender);
        e.Handled = true;
    }

    private void pp_TouchDown(object sender, TouchEventArgs e)
    {
        var pushpin = (sender as Pushpin);
        pushpin.CaptureTouch(e.TouchDevice);
        e.Handled = true;
    }

    void pp_StylusDown(object sender, StylusDownEventArgs e)
    {
        var pushpin = (sender as Pushpin);
        pushpin.CaptureStylus();
        e.Handled = true;
    }

    void pp_StylusUp(object sender, StylusEventArgs e)
    {
        var pushpin = (sender as Pushpin);
        e.Handled = true;
        if (pushpin != null && e.StylusDevice.Captured == pushpin)
        {
            PushPinUpOrDown(sender);
            pushpin.ReleaseStylusCapture();
        }

    }

    void pp_TouchUp(object sender, TouchEventArgs e)
    {
        var pushpin = (sender as Pushpin);
        e.Handled = true;
        if (pushpin != null && e.TouchDevice.Captured == pushpin)
        {
            PushPinUpOrDown(sender);
            pushpin.ReleaseTouchCapture(e.TouchDevice);

        }
    }

但是当我触摸我的PushPin 时,首先触发StylusDown 事件,然后触发MouseDown。我希望触发的TouchDown 事件永远不会触发。

这是为什么?这是我的程序或显示器的问题吗?

我需要 Stylus 和 Touch 事件吗?

(我使用的是触控显示器,而不是平板电脑或其他任何东西)

【问题讨论】:

    标签: c# wpf events touch


    【解决方案1】:

    所以从here我得到了代码:

        void pp_StylusDown(Object sender, StylusEventArgs e)
        {
            if (sender != null)
            {
                //Capture the touch device (i.e. finger on the screen)
                e.StylusDevice.Capture(sender as Pushpin);
            }
        }
    
        void pp_StylusUp(Object sender, StylusEventArgs e)
        {
            var device = e.StylusDevice;
    
            if (sender != null && device.Captured == sender as Pushpin)
            {
                (sender as Pushpin).ReleaseStylusCapture();
                PushPinUpOrDown(sender, true);
                e.Handled = true;
            }
        }
    

    它停止了MouseDown 事件的触发。主要原因(奇怪)是从pp_StylusDown 中删除e.Handled = true 解决了问题

    仍然没有解释为什么触屏时触笔事件会触发

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-02-23
      • 2010-10-21
      • 2012-02-20
      • 1970-01-01
      相关资源
      最近更新 更多