TouchDown事件不断被提升为MouseLeftButton事件

时间:2014-11-14 13:16:07

标签: wpf touch windows-8.1

在Windows 8上运行的WPF应用程序中,TouchDown事件始终会提升为MouseLeftButton事件。我不知道为什么,也想避免这种情况。

这是一个完整的示例代码:

XAML

<Window x:Class="TestTouchAndMouse.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        Title="MainWindow" Height="350" Width="525"
        Stylus.IsPressAndHoldEnabled="False">
    <Canvas x:Name="MyCanvas" Background="White" IsManipulationEnabled="False">
        <TextBox x:Name="TB" InkCanvas.Top="50" InkCanvas.Left="10" FontSize="20" />
    </Canvas>
</Window>

C#

namespace TestTouchAndMouse
{
    public partial class MainWindow : Window
    {
        public MainWindow()
        {
            InitializeComponent();
            MyCanvas.MouseLeftButtonDown += MyCanvas_MouseLeftButtonDown;
            MyCanvas.MouseRightButtonDown += MyCanvas_MouseRightButtonDown;
            MyCanvas.TouchDown += MyCanvas_TouchDown;
        }

         void MyCanvas_MouseRightButtonDown(object sender, MouseButtonEventArgs e)
         {
             e.Handled = true;
             TB.Text = "MOUSE RIGHT !";
         }
         void MyCanvas_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
         {
             e.Handled = true;
             TB.Text = "MOUSE LEFT !";
         }
         void MyCanvas_TouchDown(object sender, TouchEventArgs e)
         {
             e.Handled = true;
             TB.Text = "TOUCH !";
         }
     }
}

在Windows 7上

  • 一切正常。

在Windows 8上

  • MouseLeftButton或MouseRightButton事件将显示&#34;鼠标离开!&#34;或者&#34;鼠标右键!&#34;正如所料。
  • TouchDown活动会非常快速地显示&#34;触摸!&#34;然后文本将变为&#34;鼠标离开!&#34;。

0 个答案:

没有答案