c# - WPF MouseButtonEventArgs Timestamp 值为负数?

标签 c# wpf triggers mouseevent

我有一些用于检查双击的 WPF 触发器的代码:

private void HandleButtonUp(object sender, MouseButtonEventArgs mouseEventArgs)
    {
        if (mouseEventArgs.ChangedButton == MouseButton.Left &&
            (mouseEventArgs.Timestamp - _lastClick) < SystemInfo.DoubleClickTime)
        {
            this.InvokeActions(mouseEventArgs);
            _lastClick = 0; // Require 2 clicks again
        }
        else 
            _lastClick = mouseEventArgs.Timestamp;
    }

到目前为止,这一直运作良好。但是今天,突然单击一下就会调用该操作。当我检查代码时,我发现时间戳值是,这导致它总是小于 SystemInfo.DoubleClickTime(我设置的是 500)。

这正常吗?怎么突然变了?

最佳答案

InputEventArgs.Timestamp 属性的行为类似于 Environment.TickCount ,您可以在其中找到以下备注:

The value of this property is derived from the system timer and is stored as a 32-bit signed integer. Consequently, if the system runs continuously, TickCount will increment from zero to Int32.MaxValue for approximately 24.9 days, then jump to Int32.MinValue, which is a negative number, then increment back to zero during the next 24.9 days.

TickCount is different from the Ticks property, which is the number of 100-nanosecond intervals that have elapsed since 1/1/0001, 12:00am.

Use the DateTime.Now property to obtain the current local date and time on this computer.

忽略跳跃发生的罕见情况(24.9 天后,然后每 49.7 天),您可以这样检查:

Math.Abs(mouseEventArgs.Timestamp - _lastClick) < SystemInfo.DoubleClickTime

关于c# - WPF MouseButtonEventArgs Timestamp 值为负数?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17834010/

相关文章:

WPF 拖放列表框

mysql - 根据另一个表触发器的条件更新表

postgresql - 获取调用某个函数的所有触发器

c# - WPF 可以在 winforms 工作的任何地方工作吗? (xp,vista, 7)

c# - WCF:客户端发送值但服务器收到空字符串

c# - MediatR 行为的约束违反异常

绑定(bind)到枚举时的 WPF ComboBox SelectedItem

c# - 如何在两个项目共享的 xaml 文件中添加用户控件的引用

c# - 在 C#/WPF 中确定控件类型的最有效方法

更新前的 MySQL 使用 PhpMyAdmin 触发插入语法错误