Exemplo n.º 1
0
        private void OnPreviewTouchMove(object sender, RoutedEventArgs e)
        {
            if (firstMouseDownHash == GetHashCode())
            {
                var cursorLocation = new Point();

                if (e is TouchEventArgs)
                {
                    cursorLocation = (e as TouchEventArgs).GetTouchPoint(this).Position;
                }
                else if (e is MouseEventArgs)
                {
                    cursorLocation = (e as MouseEventArgs).GetPosition(this);
                }

                var x = cursorLocation.X;
                var y = cursorLocation.Y;

                if (x < 0 || x > ActualWidth || y < 0 || y > ActualHeight)
                {
                    firstMouseDownHash = -1;
                    PressHold?.Invoke(this, new PressHoldEventArgs(PressHoldEventArgs.EventType.Release));
                    IsPressedInternal   = false;
                    IsMouseOverInternal = false;
                }
                else if (e is MouseEventArgs && Mouse.LeftButton != MouseButtonState.Pressed)
                {
                    IsMouseOverInternal = true;
                }
            }

            e.Handled = true;
        }
Exemplo n.º 2
0
        private void OnPreviewRelease(object sender, RoutedEventArgs e)
        {
            var exec = IsPressedInternal && firstMouseDownHash == GetHashCode();

            ReleaseAllTouchCaptures();
            ReleaseMouseCapture();

            if (firstMouseDownHash == GetHashCode())
            {
                firstMouseDownHash = -1;
            }

            PressHold?.Invoke(this, new PressHoldEventArgs(PressHoldEventArgs.EventType.Release));

            if (exec)
            {
                OnClick();
            }

            if (IsMouseOver && e is MouseButtonEventArgs)
            {
                IsMouseOverInternal = true;
            }

            IsPressedInternal = false;
            e.Handled         = true;
        }
Exemplo n.º 3
0
        private async void OnPreviewPress(object sender, RoutedEventArgs e)
        {
            if (!IsEnabled)
            {
                return;
            }

            if (firstMouseDownHash == -1)
            {
                firstMouseDownHash = GetHashCode();
                IsPressedInternal  = true;

                if (e is MouseButtonEventArgs)
                {
                    PreviewMouseLeftButtonDown?.Invoke(sender, e as MouseButtonEventArgs);
                }
                else if (e is TouchEventArgs)
                {
                    PreviewTouchDown?.Invoke(sender, e as TouchEventArgs);
                }

                PressHold?.Invoke(this, new PressHoldEventArgs(PressHoldEventArgs.EventType.Press));
                if (LongPressEnabled)
                {
                    var longPressMSec      = LongPressDelay.TotalMilliseconds;
                    var longPressStep      = 10;
                    var longPressStepDelay = longPressMSec / longPressStep;

                    while (longPressMSec > 0)
                    {
                        if (firstMouseDownHash == -1)
                        {
                            break;
                        }
                        await Task.Delay(TimeSpan.FromMilliseconds(longPressStepDelay));

                        longPressMSec -= longPressStepDelay;
                    }

                    if (firstMouseDownHash == GetHashCode())
                    {
                        ReleaseAllTouchCaptures();
                        ReleaseMouseCapture();

                        firstMouseDownHash = -1;
                        LongPress?.Invoke(this, e);
                        IsPressedInternal = false;
                        e.Handled         = true;
                    }
                }
            }
        }
Exemplo n.º 4
0
        private void OnLeave(object sender, RoutedEventArgs e)
        {
            if (firstMouseDownHash == GetHashCode())
            {
                ReleaseAllTouchCaptures();
                ReleaseMouseCapture();

                firstMouseDownHash = -1;
                PressHold?.Invoke(this, new PressHoldEventArgs(PressHoldEventArgs.EventType.Release));
                IsPressedInternal = false;
            }

            IsMouseOverInternal = false;

            e.Handled = true;
        }