wp wp8: gesture GuestureService/GuestureListener

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("double click");
        }

        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("Pinch action.. ." + d);
           
        }

        private void onPinchCompleted(object sender, PinchGestureEventArgs e)
        {
            System.Diagnostics.Debug.WriteLine("Pinch action ends");
        }

    }
}



This demo adds a picture, zooms and scales the picture drag and drop

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326355793&siteId=291194637
WP2