簡単なテストを行ったところです。これを行う 1 つの方法は、グローバル イベント ハンドラーを作成することです。
TouchEventArgs
およびMouseButtonEventArgs
から派生するためInputEventArgs
、グローバルハンドラーは実装するだけですInputEventArgs
/// <summary>
/// Interaction logic for MainWindow.xaml
/// </summary>
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
}
//private void Button_TouchMove(object sender, TouchEventArgs e)
//{
// TouchEventArgs derives from InputEventArgs
//}
// private void Button_MouseMove(object sender, MouseButtonEventArgs e)
//{
// MouseButtonEventArgs derives from InputEventArgs
//}
private void GlobalHandler(object sender, InputEventArgs e)
{
// This will fire for both TouchEventArgs and MouseButtonEventArgs
// If you need specific information from the event args you can just cast.
// e.g. var args = e as MouseButtonEventArgs;
}
}
Xaml:
<Window x:Class="WpfApplication3.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">
<Grid >
<Button MouseMove="GlobalHandler" TouchMove="GlobalHandler"/>
</Grid>
</Window>
お役に立てれば