很简单,我在 WPF4 中的 UserControl 上接收 TouchDown 事件时遇到了不可接受的延迟。我对事件堆栈的理解是 PreviewTouchDown 先发送,但仍然需要大约 300ms-500ms。代码如下。
<UserControl x:Class="MyButton"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
mc:Ignorable="d"
d:DesignHeight="300"
d:DesignWidth="300"
Stylus.IsPressAndHoldEnabled="False"
PreviewTouchDown="ProcessPreviewTouchDown"
PreviewTouchUp="ProcessPreviewTouchUp">
</UserControl>
我还在我的窗口代码中添加了以下内容:
num = GlobalAddAtom(atom);
if (num == 0L)
{
return false;
}
if (enable)
{
return (RemoveProp(hWnd, atom).ToInt64() == 1L);
}
else
{
int TABLET_DISABLE_PRESSANDHOLD = 0x00000001;
int TABLET_DISABLE_PENTAPFEEDBACK = 0x00000008;
int TABLET_DISABLE_PENBARRELFEEDBACK = 0x00000010;
int TABLET_DISABLE_TOUCHUIFORCEOFF = 0x00000200;
int TABLET_DISABLE_FLICKS = 0x00010000;
int dwHwndTabletProperty = 0x1010019 |
TABLET_DISABLE_PRESSANDHOLD |
TABLET_DISABLE_PENTAPFEEDBACK |
TABLET_DISABLE_TOUCHUIFORCEOFF |
TABLET_DISABLE_PENBARRELFEEDBACK |
TABLET_DISABLE_FLICKS;
return (SetProp(hWnd, atom, new IntPtr(dwHwndTabletProperty)) == 1);
}
这肯定会删除 UI,但不会导致明显的速度增加(即使 TABLET_DISABLE_PRESSANDHOLD 应该这样做,但我怀疑这与添加Stylus.IsPressAndHoldEnabled="False"
到 XAML 相同)。
如果有人对如何使这种延迟消失有任何指示,我将不胜感激。