捕获鼠标按钮.XButton1/2用于前向/后向导航Windows 10

本文关键字:导航 Windows 鼠标 按钮 XButton1 用于 | 更新日期: 2023-09-27 17:57:36

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

在Windows10中,我可以使用捕捉鼠标点击

this.PointerPressed += LevelsPage_PointerPressed;
private void LevelsPage_PointerPressed(object sender, Windows.UI.Xaml.Input.PointerRoutedEventArgs e)
    {
        if (e.Pointer.PointerDeviceType == PointerDeviceType.Mouse)
        { 
        }
    }

但是,我如何确定指针是MouseButtons.XButton,或者更确切地说,PointerRoutedEventArgs的类型是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;
        }

捕获鼠标按钮.XButton1/2用于前向/后向导航Windows 10

我想明白了。以下是我的操作方法

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