windows phone 之手势识别(Manipulation)

时间:2023-03-09 05:53:47
windows phone 之手势识别(Manipulation)

在Windows Phone 7的多触摸屏上可以检测到至少四根同时存在的手指,并且一起操作使触摸屏充分发挥效果。

在silverlight开发中通过事件来实现触屏事件的检测,包括低级别的和高级别的接口。

(1)低级别主要是FrameReported 事件,是Page页面

Touch.FrameReported += OnTouchFrameReported; 
FrameReported事件是静态 Touch 类的唯一公共成员。处理程序如下所示:

voidOnTouchFrameReported( object sender, TouchFrameEventArgsargs) 

{

  .......

}

(2)高级别的是定义在UIElement类中的事件,包含ManipulationStarted,Manipulationdelta,ManipulationCompleted,这三个事件互相配合来完成触控操作,它们可以在任何UIElement的子类中使用。

今天这讲是Manipulation事件。

一、事件说明

  1.ManipulationStarted事件

  当手指按下触摸屏时发生

  2.Manipulationdelta

  当手指在触摸屏移动时发生

  3.ManipulationCompleted

  当手指释放触摸屏时发生

在XAML代码中,

<Grid x:Name="LayoutRoot" Background="Transparent"  ManipulationStarted="LayoutRoot_ManipulationStarted" ManipulationDelta="LayoutRoot_ManipulationDelta" ManipulationCompleted="LayoutRoot_ManipulationCompleted">
        <Grid.RenderTransform>
            <CompositeTransform  x:Name="transform"/>
        </Grid.RenderTransform>
        <Grid.RowDefinitions>
            <RowDefinition Height="Auto"/>
            <RowDefinition Height="*"/>
        </Grid.RowDefinitions>

在XAML.CS代码中添加事件处理程序:

如下:

 private void LayoutRoot_ManipulationStarted(object sender, ManipulationStartedEventArgs e)
        {

        }

        private void LayoutRoot_ManipulationDelta(object sender, ManipulationDeltaEventArgs e)
        {
             transform.TranslateX += e.DeltaManipulation.Translation.X;
            transform.TranslateY = ;
        }

        private void LayoutRoot_ManipulationCompleted(object sender, ManipulationCompletedEventArgs e)
        {
           //ContentPanel容器总转换的线性运动的X坐标值〉=100
            )
            {
                num--;
               oisdnco(num);
            }
            )
            {
                num++;
                oisdnco(num);
            }
            transform.TranslateX = ;
        }

ok了。