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

标签 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.XButton 还是 PointerRoulatedEventArgs 的类型是 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;
        }

最佳答案

我明白了。我是这样做的

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

    }

关于c# - 捕获 MouseButtons.XButton1/2 用于向前/向后导航 Windows 10,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38429956/

相关文章:

node.js - 为什么我的 'npm start' 脚本导致错误 : '.' is not recognized as an internal or external command, 可运行程序或批处理文件。?

c# - OLEDBConnection.Open() 生成 'Unspecified error'

c# - 在另一个具有不同对象数据类型的列表中排除一个列表的项目,LINQ?

html - IE7、HTML - 为什么只需将鼠标移出容器即可解决溢出问题?

windows - 如何为 Windows 构建或获取原始最新版本的 GCC?

c# - 如何在 Windows Universal 10 App 中无异常地获取 StackTrace

c# - c# 中的 HttpWebRequest 不适用于 .net 4.5

c# - 具有 Azure 辅助角色的 Ninject

flash - AS3 Video MouseEvent Click 不起作用

java - 创建鼠标移动可视化效果最丰富的方法是什么?