很简单,我在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相同)。
如果有人对如何使这种延迟消失有任何指示,我将非常感激。