====== 008 タッチイベントの検出 ====== {{:wiki:windowsphone:7.1:tips:w_phone_008_001.png?200|}} ===== 概要 ===== 画面のタッチイベントを検出し、開始時、操作中、終了時の座標を表示します。 ==== MainPage.xaml ==== ==== MainPage.xaml.cs ==== using System; using System.Collections.Generic; using System.Linq; using System.Net; using System.Windows; using System.Windows.Controls; using System.Windows.Documents; using System.Windows.Input; using System.Windows.Media; using System.Windows.Media.Animation; using System.Windows.Media.Imaging; using System.Windows.Shapes; using Microsoft.Phone.Controls; namespace BaseApp { // エントリーポイント public partial class MainPage : PhoneApplicationPage { private TextBlock textBlock0 = null; // コンストラクタ public MainPage() { // コンポーネントの初期化。 InitializeComponent(); // 初期化完了後に呼ばれるメソッドの登録。 Loaded += OnLoaded; } // 初期化完了後に呼ばれるメソッド。 void OnLoaded(object sender, RoutedEventArgs args) { { // 文字列の表示。 textBlock0 = new TextBlock(); textBlock0.FontFamily = new FontFamily("MS ゴシック"); // フォントタイプ。 textBlock0.FontSize = 32; // フォントサイズ。 textBlock0.FontStretch = FontStretches.Normal; // 伸縮率。 textBlock0.FontStyle = FontStyles.Normal; // フォントスタイル。 textBlock0.FontWeight = FontWeights.Bold; // フォントスタイル。 SolidColorBrush brush = new SolidColorBrush(Color.FromArgb(255, 255, 255, 255)); textBlock0.Foreground = brush; textBlock0.Text = "Please touch Screen"; Canvas.SetLeft(textBlock0, 0); Canvas.SetTop(textBlock0, 0); LayoutRoot.Children.Add( textBlock0 ); } } // タッチ開始時に呼ばれるメソッド。 protected override void OnManipulationStarted(ManipulationStartedEventArgs e) { textBlock0.Text = "StartX = " + e.ManipulationOrigin.X + "\n" + "StartY = " + e.ManipulationOrigin.Y; } // タッチしたまま指を動かした時に呼ばれるメソッド。 protected override void OnManipulationDelta(ManipulationDeltaEventArgs e) { textBlock0.Text = "MoveX = " + e.ManipulationOrigin.X + "\n" + "MoveY = " + e.ManipulationOrigin.Y; } // タッチ終了時に呼ばれるメソッド。 protected override void OnManipulationCompleted(ManipulationCompletedEventArgs e) { textBlock0.Text = "EndX = " + e.ManipulationOrigin.X + "\n" + "EndY = " + e.ManipulationOrigin.Y; } } }