基本上,一個簡單的應用程序,當用戶觸摸屏幕時,屏幕上的計數器遞增。我沒有觸摸輸入的經驗,也沒有任何關於如何正確構建觸摸輸入的知識。至於我應該使用什麼方法或對象,我什麼也不知道。使用按鈕,觸摸會自動註冊。所以,我想與Windows Phone 8的使用Visual Studio 2013年至今在屏幕上也這樣做,這是C#代碼我迄今與它是什麼樣子的移動顯示器上的圖像:如何在C#中進行觸摸輸入?
public partial class MainPage : PhoneApplicationPage
{
int taps = 0; // create var to detect number of times, user touches the screen
// Constructor
public MainPage()
{
InitializeComponent();
}
// method to register the touch as the finger is placed on the screen
private void Canvas_MouseLeftButtonDown(object sender, System.Windows.Input.MouseButtonEventArgs e)
{
//Canvas c = sender as Canvas;
}
//method register the touch as the finger is lifting up from the screen
private void Canvas_MouseLeftButtonUp(object sender, System.Windows.Input.MouseButtonEventArgs e)
{
//Canvas c = sender as Canvas;
taps++;
counter.Text = taps.ToString(); //convert var from int to string
}
//method register the touch as the finger leaves the area of the screen
private void Canvas_MouseLeave(object sender, System.Windows.Input.MouseEventArgs e)
{
//Canvas c = sender as Canvas;
MessageBox.Show("You left the screen without lifting your finger. That does not count as a tap!", "Caution!", MessageBoxButton.OK);
}
// method to reset the counter to zero when button is pressed and released
private void Button_Click(object sender, RoutedEventArgs e)
{
taps = 0; // reset the count
counter.Text = taps.ToString(); // convert var from int to string
}
這個問題很相似,你的第二個:http://stackoverflow.com/questions/21621670/how-to-make-the-canvas-detect點觸摸輸入-適當-在-C/21624239#21624239 – Romasz