ユーザ用ツール

サイト用ツール

サイドバー

About

Contents

Materials Link

その他

PR


wiki:windowsphone:7.1:tips:008

008 タッチイベントの検出

概要

画面のタッチイベントを検出し、開始時、操作中、終了時の座標を表示します。

MainPage.xaml

<phone:PhoneApplicationPage 
	x:Class="BaseApp.MainPage"
	xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
	xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
	xmlns:phone="clr-namespace:Microsoft.Phone.Controls;assembly=Microsoft.Phone"
	xmlns:shell="clr-namespace:Microsoft.Phone.Shell;assembly=Microsoft.Phone"
	xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
	xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
	mc:Ignorable="d" d:DesignWidth="480" d:DesignHeight="768"
	FontFamily="{StaticResource PhoneFontFamilyNormal}"
	FontSize="{StaticResource PhoneFontSizeNormal}"
	Foreground="{StaticResource PhoneForegroundBrush}"
	SupportedOrientations="Portrait" Orientation="Portrait"
	shell:SystemTray.IsVisible="True">
 
	<!--LayoutRoot is the root grid where all page content is placed-->
	<Grid x:Name="LayoutRoot" Background="Transparent">
		<Grid.RowDefinitions>
			<RowDefinition Height="Auto"/>
			<RowDefinition Height="*"/>
		</Grid.RowDefinitions>
 
		<!--ContentPanel - place additional content here-->
		<Grid x:Name="ContentPanel" Grid.Row="1" Margin="12,0,12,0"></Grid>
	</Grid>
</phone:PhoneApplicationPage>

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;
		}
	}
}
Permalink wiki/windowsphone/7.1/tips/008.txt · 最終更新: 2014/11/08 03:02 (外部編集)

oeffentlich