ATTENZIONE: Questo sito impiega diversi tipi di cookies. Alla pagina MAGGIORI INFORMAZIONI è possibile avere informazioni aggiuntive. Cliccando su ACCETTO o continuando a navigare sul sito acconsenti al loro utilizzo.
<settembre 2021>
lunmarmergiovensabdom
303112345
6789101112
13141516171819
20212223242526
27282930123
45678910
Immagini  

UniversalApp - Gestione Gesture

Supponendo di gestire lo SWIPE orizzontale per un componente, i passi da seguire sono questi

 

  1. Nello XAML, aggiungere al TAG UI l'attributo ManipulationMode="xxxxx" (valori possibili: All, None, Rotate, RotateInertia, Scale, ScaleInertia, System, TranslateInertia, TranslateRailsX, TranslateRailsY, TranslateX, TranslateY)
    1. Nel caso di SWIPE orizzontale, scegliere TranslateX
  2. Nel codice aggiungere le seguenti variabili globali della pagine/Usercontrol

     private TransformGroup _transformGroup;

        private MatrixTransform _previousTransform;

        private CompositeTransform _compositeTransform;

        private bool forceManipulationsToEnd;

        private bool hasMovedRight;

        private bool hasMovedLeft;

 

  1. Modificare il costruttore come segue, e aggiungere i metodi come nell'esempio

        public ucAlbum()

        {

            this.InitializeComponent();

            forceManipulationsToEnd = false;

            hasMovedRight = false;

            hasMovedLeft = false;

            gAlbum.ManipulationStarting += new ManipulationStartingEventHandler(gAlbum_ManipulationStarting);

            gAlbum.ManipulationStarted += new ManipulationStartedEventHandler(gAlbum_ManipulationStarted);

            gAlbum.ManipulationDelta += new ManipulationDeltaEventHandler(gAlbum_ManipulationDelta);

            gAlbum.ManipulationCompleted += new ManipulationCompletedEventHandler(gAlbum_ManipulationCompleted);

            gAlbum.ManipulationInertiaStarting += new ManipulationInertiaStartingEventHandler(gAlbum_ManipulationInertiaStarting);

            ManipulationReset();

        }

 

        void ManipulationReset()

        {

            forceManipulationsToEnd = true;

            hasMovedRight = false;

            hasMovedLeft = false;

            gAlbum.RenderTransform = null;

            InitManipulationTransforms();

        }

 

        private void InitManipulationTransforms()

        {

            _transformGroup = new TransformGroup();

            _compositeTransform = new CompositeTransform();

            _previousTransform = new MatrixTransform() { Matrix = Matrix.Identity };

 

            _transformGroup.Children.Add(_previousTransform);

            _transformGroup.Children.Add(_compositeTransform);

 

            gAlbum.RenderTransform = _transformGroup;

        }

 

        void gAlbum_ManipulationStarting(object sender, ManipulationStartingRoutedEventArgs e)

        {

            forceManipulationsToEnd = false;

            e.Handled = true;

        }

 

        void gAlbum_ManipulationStarted(object sender, ManipulationStartedRoutedEventArgs e)

        {

            e.Handled = true;

        }

 

        void gAlbum_ManipulationInertiaStarting(object sender, ManipulationInertiaStartingRoutedEventArgs e)

        {

            e.Handled = true;

        }

 

        void gAlbum_ManipulationDelta(object sender, ManipulationDeltaRoutedEventArgs e)

        {

            if (forceManipulationsToEnd)

            {

                e.Complete();

                return;

            }

            //hasMovedRight = true;

 

            if (e.Delta.Translation.X < 0) hasMovedLeft = true;

            else hasMovedRight = true;

           

 

            //_previousTransform.Matrix = _transformGroup.Value;

 

            //Point center = _previousTransform.TransformPoint(new Point(e.Position.X, e.Position.Y));

            //_compositeTransform.CenterX = center.X;

            //_compositeTransform.CenterY = center.Y;

 

            //_compositeTransform.Rotation = e.Delta.Rotation;

            //_compositeTransform.ScaleX = _compositeTransform.ScaleY = e.Delta.Scale;

            //_compositeTransform.TranslateX = e.Delta.Translation.X;

            //_compositeTransform.TranslateY = e.Delta.Translation.Y;

 

            e.Handled = true;

        }

        void gAlbum_ManipulationCompleted(object sender, ManipulationCompletedRoutedEventArgs e)

        {

            if (hasMovedLeft)

            {

                if (currentPage<CSticker.ALBUM_PAGES) currentPage++;

            }

            else if (hasMovedRight)

            {

                if (currentPage > 0) currentPage--;

            }

            loadAlbum();

            ManipulationReset();

            e.Handled = true;

        }

 

 

  1. In giallo è evidenziata l'azione da fare quando la gesture è finita.

Notifiche