【问题标题】:wpf stylus mouse eventwpf 手写笔鼠标事件
【发布时间】:2013-06-25 16:23:42
【问题描述】:

当 button1 被触控笔点击时,测试方法会被调用两次,即使我在 stylusdown 事件中设置了 Handled 属性。有没有办法让手写笔事件不传播辅助按钮点击事件?

namespace DialogTest
{
    /// <summary>
    /// Interaction logic for Window1.xaml
    /// </summary>
    public partial class Window1 : Window
    {
        public Window1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, RoutedEventArgs e)
        {
            test(sender, e);
        }

        private void button1_StylusDown(object sender, StylusDownEventArgs e)
        {
            test(sender, e);
            e.Handled = true;
        }

        private void test(object e, EventArgs env)
        {
            Console.WriteLine(e.ToString(), env.ToString());

            Console.WriteLine("clicking");
        }


    }

【问题讨论】:

    标签: wpf windows-7 onclick


    【解决方案1】:

    如果您查看此MSDN Input overview 文档。你会看到这两个事件都被调用了。

    从上面的链接:

    由于触控笔可以充当鼠标,因此仅支持鼠标输入的应用程序仍然可以自动获得一定程度的触控笔支持。当以这种方式使用触控笔时,应用程序有机会处理适当的触控笔事件,然后处理相应的鼠标事件。此外,还可以通过手写笔设备抽象获得更高级别的服务,例如墨水输入。

    由于它确实为您提供了调用事件的顺序,您可以创建一个布尔变量,将其设置在StylusDown EventHandler 中,然后检查您的Button_Click EventHandler,如果它为真,将其设置为假然后退出处理程序。

    类似的东西。

    public partial class Window1 : Window
    {
        bool StylusDown;
        public Window1()
        {
            InitializeComponent();
        }
    
        private void button1_Click(object sender, RoutedEventArgs e)
        {
            if(StylusDown)
            {
                StylusDown=false;
                return;
            }
    
            test(sender, e);
        }
    
        private void button1_StylusDown(object sender, StylusDownEventArgs e)
        {
            StylusDown =true;
            test(sender, e);
        }
    
        private void test(object e, EventArgs env)
        {
            Console.WriteLine(e.ToString(), env.ToString());
    
            Console.WriteLine("clicking");
        }
    
    
    }
    

    可能有更好的方法来实现这一点,但这是我想到的第一件事。

    【讨论】:

    • 非常感谢您,先生,我已经实施了您的解决方案,它就像一个魅力。
    【解决方案2】:

    MouseEventArgs 有一个名为 StylusDevice 的属性,如果事件源自触控笔或触摸事件,则该属性不为空。

    private void button1_Click(object sender, MouseButtonEventArgs e)
    {
        if (e.StylusDevice != null) return;
        ...
    }
    

    【讨论】:

      猜你喜欢
      • 2018-10-08
      • 1970-01-01
      • 1970-01-01
      • 2019-02-09
      • 2018-06-29
      • 1970-01-01
      • 2011-08-17
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多