Exemplo n.º 1
0
        private void TextblockGestureRecognizer()
        {
            var recognizer = new GestureRecognizer()
            {
                GestureSettings = GestureSettings.ManipulationScale
            };

            recognizer.ManipulationStarted += (_, __) => ViewModel.TranslatedTextFontSizePitchStart.OnNext(Unit.Default);

            recognizer.ManipulationCompleted += (_, __) => ViewModel.TranslatedTextFontSizePitchCompleted.OnNext(Unit.Default);

            recognizer.ManipulationUpdated += (_, e) =>
            {
                ViewModel.TranslatedTextFontSizePitch.OnNext(e.Cumulative.Scale);
            };

            // Panel has override router event, so we must use AddHandler
            // to add our handler

            TranslatedTextViewer.AddHandler(PointerPressedEvent,
                                            new PointerEventHandler((_, e) =>
            {
                TranslatedText.CapturePointer(e.Pointer);
                recognizer.ProcessDownEvent(e.GetCurrentPoint(TranslatedTextPanel));
            }),
                                            true);

            TranslatedTextViewer.AddHandler(PointerMovedEvent,
                                            new PointerEventHandler((_, e) =>
            {
                recognizer.ProcessMoveEvents(e.GetIntermediatePoints(TranslatedTextPanel));
            }),
                                            true);

            TranslatedTextViewer.AddHandler(PointerReleasedEvent,
                                            new PointerEventHandler((_, e) =>
            {
                recognizer.ProcessUpEvent(e.GetCurrentPoint(TranslatedTextPanel));
                TranslatedText.ReleasePointerCapture(e.Pointer);
            }),
                                            true);

            TranslatedTextViewer.AddHandler(PointerCanceledEvent,
                                            new PointerEventHandler((_, e) =>
            {
                recognizer.CompleteGesture();
                TranslatedText.ReleasePointerCapture(e.Pointer);
            }),
                                            true);
        }