wp wp8:手势GuestureService/GuestureListener
程序员文章站
2022-04-30 09:58:59
...
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添加了一张图片,对图片进行了缩放和拖拽操作
上码:
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添加了一张图片,对图片进行了缩放和拖拽操作
上一篇: wp wp8:后台任务
下一篇: html table表格 - 美女信息