上码:
MainPage.xaml
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"
FontFamily="{StaticResource PhoneFontFamilyNormal}"
FontSize="{StaticResource PhoneFontSizeNormal}"
Foreground="{StaticResource PhoneForegroundBrush}"
SupportedOrientations="Portrait" Orientation="Portrait"
shell:SystemTray.IsVisible="True"
xmlns:toolkit="clr-namespace:Microsoft.Phone.Controls;assembly=Microsoft.Phone.Controls.Toolkit"
>
DoubleTap = "onDoubleTap"
Hold="onHold"
Flick="onFlick"
DragStarted="onDragStarted"
DragDelta = "onDragDelta"
DragCompleted="onDragCompleted"
PinchStarted="onPinchStarted"
PinchDelta = "onPinchDelta"
PinchCompleted="onPinchCompleted"
>
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.Navigation;
using Microsoft.Phone.Controls;
using Microsoft.Phone.Shell;
using wp8ToolkitTouches.Resources;
namespace wp8ToolkitTouches
{
public partial class MainPage : PhoneApplicationPage
{
// 构造函数
public MainPage()
{
InitializeComponent();
}
/*
Tap="onTap"
DoubleTap = "onDoubleTap"
Hold="onHold"
Flick="onFlick"
DragStarted="onDragStarted"
DragDelta = "onDragDelta"
DragCompleted="onDragCompleted"
PinchStarted="onPinchStarted"
PinchDelta = "onPinchDelta"
PinchCompleted="onPinchCompleted"
*/
private void onTap(object sender, GestureEventArgs e)
{
System.Diagnostics.Debug.WriteLine("单击");
}
private void onDoubleTap(object sender, GestureEventArgs e)
{
System.Diagnostics.Debug.WriteLine("双击");
}
private void onHold(object sender, GestureEventArgs e)
{
System.Diagnostics.Debug.WriteLine("长按");
}
private void onFlick(object sender, GestureEventArgs e)
{
System.Diagnostics.Debug.WriteLine("轻击");
}
/*********************************************************************/
private void onDragStarted(object sender, DragStartedGestureEventArgs e)
{
System.Diagnostics.Debug.WriteLine("拖动开始");
}
private void onDragDelta(object sender, DragDeltaGestureEventArgs e)
{
tramsform.TranslateX += e.HorizontalChange;
tramsform.TranslateY += e.VerticalChange;
System.Diagnostics.Debug.WriteLine("拖动中...");
}
private void onDragCompleted(object sender, DragCompletedGestureEventArgs e)
{
System.Diagnostics.Debug.WriteLine("拖动结束");
}
/*********************************************************************/
double initialScale;
private void onPinchStarted(object sender, PinchStartedGestureEventArgs e)
{
initialScale = tramsform.ScaleX;
System.Diagnostics.Debug.WriteLine("捏动作开始");
}
private void onPinchDelta(object sender, PinchGestureEventArgs e)
{
double d = e.DistanceRatio;
//imdsf.TR
tramsform.ScaleX = tramsform.ScaleY = initialScale * d;
System.Diagnostics.Debug.WriteLine("捏动作中..." + d);
}
private void onPinchCompleted(object sender, PinchGestureEventArgs e)
{
System.Diagnostics.Debug.WriteLine("捏动作结束");
}
}
}
这个demo添加了一张图片,对图片进行了缩放和拖拽操作