在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上