我想你可以嘗試使用TouchPanel從XNA - 它工作得很好,我想會做你想要什麼:
using Microsoft.Xna.Framework.Input.Touch;
using Microsoft.Xna.Framework;
public MainPage()
{
InitializeComponent();
TouchPanel.EnabledGestures = GestureType.Tap;
this.Tap += MainPage_Tap;
}
private void MainPage_Tap(object sender, System.Windows.Input.GestureEventArgs e)
{
GestureSample gesture = TouchPanel.ReadGesture();
Vector2 vector = gesture.Position;
int positionX = (int)vector.X;
int positionY = (int)vector.Y;
}
左上角爲(0,0)和無論您的應用具有何種方向,您都會獲得相對的位置。
編輯 - 幾句話
請注意,您也可以在CompositionTarget.Rendering或定時檢查TOUCHINPUT - 這取決於你想要達到的目標。
還要注意,當你使用XNA你可能有時候需要做的:
FrameworkDispatcher.Update();
EDIT 2 - 捏例如
如果你想使用捏或其它手勢也可以是這樣的:
public MainPage()
{
InitializeComponent();
TouchPanel.EnabledGestures = GestureType.Pinch;
this.ManipulationCompleted+=MainPage_ManipulationCompleted;
}
private void MainPage_ManipulationCompleted(object sender, System.Windows.Input.ManipulationCompletedEventArgs e)
{
if (TouchPanel.IsGestureAvailable)
{
GestureSample gesture = TouchPanel.ReadGesture();
Vector2 vector = gesture.Position;
int positionX = (int)vector.X;
int positionY = (int)vector.Y;
// do what you want with your positin
// there are also some more properties in which you may be interested
// also TouchPanel has properites like TouchPanel.DisplayWidth and DisplayHeight if you need them
}
}
對於FrameworkDispatcher.Update() - 我認爲你可以叫它OnNavigetedTo()。
看起來很有趣,我會試着看看明天。並回報。 – JTIM
我試過你的代碼,看起來像它做我想要的。但這不是我需要的事件。我希望它爲捏事件。然而,我一直無法做到這一點,你能幫我把它轉換爲使用捏來代替嗎?還FrameworkDispatcher.Update,應該何時調用? – JTIM
@JTIM我在編輯2中添加了,你問了什麼。另請參閱其他手勢類型,也許您會對它們感興趣。我也添加捏到ManipulationCompleted - 請注意,它可以是ManipalationStarted,或delta,如果你需要它們。 – Romasz