WPF中的鼠标额外按钮

5
在WPF中,是否可以捕获鼠标的额外按钮点击?我想在我的应用程序中使用鼠标实现后退和前进导航,就像在浏览互联网时一样。当单击额外按钮时,我想执行一个命令。 我只能找到使用左/右/轮按钮的示例。提前感谢。

2
请看这个链接:https://dev59.com/GFjUa4cB1Zd3GeqPQE-N - Hossein Narimani Rad
非常感谢,现在我只需要在适当的按钮被点击时执行我的命令。 - dbostream
在此处添加了一个答案:https://dev59.com/GFjUa4cB1Zd3GeqPQE-N#69612409 - Christoffer Lette
1个回答

5
在构造函数中:
  MouseDown += MouseDownEvent;

事件处理程序:
  private void MouseDownEvent(object sender, MouseButtonEventArgs e)
  {
        switch (e.ChangedButton)
        {
             case MouseButton.XButton1://Back button
                MessageBox.Show("Back button pressed");
                break;
             case MouseButton.XButton2://forward button
                MessageBox.Show("Forward button pressed");
                break;
             default:
                break;
        }
  }

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接