捕获MouseButtons.XButton1 / 2用于向前/向后导航Windows 10

时间:2016-07-18 06:33:13

标签: c# mouseevent windows-10 windows-10-universal

我想捕获MouseButtons.XButton 1和2并启用向后和向前导航。

在Windows 10中,我可以使用

捕获鼠标点击
this.PointerPressed += LevelsPage_PointerPressed;
private void LevelsPage_PointerPressed(object sender, Windows.UI.Xaml.Input.PointerRoutedEventArgs e)
    {
        if (e.Pointer.PointerDeviceType == PointerDeviceType.Mouse)
        { 

        }
    }

但我如何确定指针MouseButtons.XButtonPointerRoutedEventArgs的类型为MouseEventArgs?一旦确定,我计划使用类似

的方式处理导航
        if (pointer == MouseButton.XButton2 && this.Frame.CanGoBack)
        {
            this.Frame.GoBack();
            e.Handled = true;
        }
        else if (pointer == MouseButton.XButton1 && this.Frame.CanGoForward)
        {
            this.Frame.GoForward();
            e.Handled = true;
        }

1 个答案:

答案 0 :(得分:0)

我明白了。这是我的工作方式

    private void LevelsPage_PointerPressed(object sender, PointerRoutedEventArgs e)
    {
        PointerPoint currentPoint = e.GetCurrentPoint(this);
        if (currentPoint.PointerDevice.PointerDeviceType == PointerDeviceType.Mouse)
        {
            PointerPointProperties pointerProperties = currentPoint.Properties;

            if (pointerProperties.IsXButton1Pressed && this.Frame.CanGoBack)
            {
                this.Frame.GoBack();                    
            }
            else if (pointerProperties.IsXButton2Pressed && this.Frame.CanGoForward)
            {
                this.Frame.GoForward();
            }
        }

    }