在WPF中禁用Windows 7触摸动画

时间:2009-11-14 02:04:51

标签: wpf animation

在Windows 7中,当您触摸屏幕时,会在触摸点发生短动画。

在我的WPF应用程序中,我想显示自己的触摸点,而不显示Windows提供的触摸点。

有关如何在应用中禁用它们的任何想法?

2 个答案:

答案 0 :(得分:4)

您可以在每个控件的基础上禁用它们,但最好的选择是,特别针对您的特定情况,如果在根应用程序的窗口中执行此操作,以及任何衍生的窗口(包括弹出窗口)。将以下附加属性添加到XAML文件中的“”元素,因此最终得到如下内容:

<Window x:Class="MyWPFTouchFreeApp"
... [<omitted elements>]
Stylus.IsTapFeedbackEnabled="False" Stylus.IsTouchFeedbackEnabled="False"
Stylus.IsPressAndHoldEnabled="False" Stylus.IsFlicksEnabled="False"
... [<any other omitted attributes>]
>
  <Grid ...

  </Grid>
</Window>

此外,如果你使用Microsoft Surface Toolkit for Windows Touch(目前处于测试阶段),使用SurfaceWindow会自动为你禁用这些(弹出窗口仍然必须手动处理)。

答案 1 :(得分:1)

今天发现这一点,同时看一下Surface Touch for Windows Touch,似乎很好地完成了这项工作。

// override on the Window class
protected override void OnSourceInitialized(EventArgs e)
{
    EnableTabletGestures(this, false);
}

[DllImport("kernel32.dll", CharSet = CharSet.Unicode)]
public static extern short GlobalAddAtom(string atom);

[DllImport("user32.dll", CharSet = CharSet.Unicode)]
public static extern IntPtr RemoveProp(IntPtr hWnd, string atom);

[DllImport("user32.dll", CharSet = CharSet.Unicode)]
public static extern int SetProp(IntPtr hWnd, string atom, IntPtr handle);

public bool EnableTabletGestures(Window window, bool enable)
{
    var hWnd = ((HwndSource)PresentationSource.FromVisual(window)).Handle;

    long num = 0L;
    string atom = "MicrosoftTabletPenServiceProperty";
    num = GlobalAddAtom(atom);
    if (num == 0L)
    {
        return false;
    }
    if (enable)
    {
        return (RemoveProp(hWnd, atom).ToInt64() == 1L);
    }
    int num2 = 0x1010019;
    return (SetProp(hWnd, atom, new IntPtr(num2)) == 1);
}