wp wp8:手势GuestureService/GuestureListener

本文介绍了一个使用Silverlight Toolkit实现的手势识别示例,包括单击、双击、长按、轻击、拖动及缩放等操作,并展示了如何通过代码响应这些手势。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

1.利用Silverlight Tookit中提供的手势服务监听进行处理

上码:

MainPage.xaml

<phone:PhoneApplicationPage
x:Class="wp8ToolkitTouches.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"
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"
>

<Grid x:Name="LayoutRoot" Background="Transparent">

<Image Width="200" Height="200" Source="/Assets/1.png" x:Name="imdsf">
<Image.RenderTransform>
<CompositeTransform x:Name="tramsform"></CompositeTransform>
</Image.RenderTransform>
</Image>

<toolkit:GestureService.GestureListener>
<toolkit:GestureListener
Tap="onTap"
DoubleTap = "onDoubleTap"
Hold="onHold"
Flick="onFlick"
DragStarted="onDragStarted"
DragDelta = "onDragDelta"
DragCompleted="onDragCompleted"
PinchStarted="onPinchStarted"
PinchDelta = "onPinchDelta"
PinchCompleted="onPinchCompleted"
>
</toolkit:GestureListener>
</toolkit:GestureService.GestureListener>

</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.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添加了一张图片,对图片进行了缩放和拖拽操作
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值