我想只为鼠标操作处理按钮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
...
}
答案 0 :(得分:1)
您可以查看最近的输入设备
if (InputManager.Current.MostRecentInputDevice is KeyboardDevice);
如下所述:
How to tell if a button click event was triggered by keyboard or mouse in WPF?