【问题标题】:WPF MouseEnter event is fired if spacebar is pressed如果按下空格键,则会触发 WPF MouseEnter 事件
【发布时间】:2015-05-18 10:39:48
【问题描述】:

我只想为鼠标操作处理按钮MouseEnter 事件。所以我要检测MouseEnter是鼠标触发还是键盘触发。

private void button_onMouseEnter(object sender, MouseEventArgs e)
{
    Button button = (Button)sender;

    if (!button.IsMouseOver)            return; // not working
    if (!button.IsMouseDirectlyOver)    return; // not working
    ...
}

【问题讨论】:

    标签: c# wpf button event-handling mouseenter


    【解决方案1】:

    您可以检查最近的输入设备

    if (InputManager.Current.MostRecentInputDevice is KeyboardDevice);
    

    这里已经讨论过:

    How to tell if a button click event was triggered by keyboard or mouse in WPF?

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2013-07-23
      • 1970-01-01
      • 2023-03-03
      • 2012-09-04
      • 1970-01-01
      • 2021-05-11
      • 2014-03-03
      相关资源
      最近更新 更多