【问题标题】:How do I prevent touch feedback on a Winforms WebBrowser in WPF?如何防止 WPF 中 Winforms WebBrowser 的触摸反馈?
【发布时间】:2016-10-12 17:16:26
【问题描述】:

我在我的 WPF 应用程序中使用 <WebBrowser> 的 WinForms 版本,a la <WindowsFormsHost> 因为总的来说它比 Windows.Controls 版本好得多。但是我有一个与触摸屏有关的问题。

通常我在控件上设置ManipulationBoundaryFeedback 事件处理程序以立即处理事件,从而防止任何边界反馈,我尝试使用以下代码来做到这一点:

MainWindow.xaml

<WindowsFormsHost IsManipulationEnabled="True" ManipulationBoundaryFeedback="WindowsFormsHost_OnManipulationBoundaryFeedback">
    <forms:WebBrowser />
</WindowsFormsHost>

MainWindow.xaml.cs

private void WindowsFormsHost_OnManipulationBoundaryFeedback(object sender, ManipulationBoundaryFeedbackEventArgs e)
{
    e.Handled = true;
}

在普通的 WPF 控件上,一般来说,这是可行的。而我所说的“作品”是指如果你用手指在触摸屏上向上或向下拖动,你不会得到触摸屏的效果intertia;也就是说,一旦您到达边界,它不会向上或向下移动 整个窗口

这里有一张图片来说明正在发生的事情:

如您所见,如果我在浏览器中向下拖动,它会拉动整个窗口。我能做些什么来防止这种情况发生?

【问题讨论】:

  • 你试过用OnManipulationBoundaryFeedback代替吗?
  • @Night5h4d3 你的评论有错别字吗?因为这就是我使用的字面意思。
  • 对不起;您是否尝试将事件处理程序添加到 Web 浏览器标签?
  • 该控件的 Windows 窗体版本没有 ManipulationBoundaryFeedback 事件;操作事件是 WPF 的一部分(WinForms 早于它)
  • 在这种情况下,您需要为WM_Gesture message 编写特殊处理。 thisthis 可能会有所帮助。

标签: c# .net wpf winforms xaml


【解决方案1】:

不确定您是否仍然需要这个答案,但为了防止这种不必要的行为,只需继承 WindowsFormsHost 类并像这样覆盖 OnManipulationBoundaryFeedback

public class MyClass : WindowsFormsHost
{

    // Override is optional to remove unnecessary behavior
    protected override void OnManipulationBoundaryFeedback(ManipulationBoundaryFeedbackEventArgs e)
    {
        // uncomment this to use base class implementation
        //base.OnManipulationBoundaryFeedback(e); 
        e.Handled = true;
    }
}

已编辑

我做了一个小测试,并为我的控件添加了这段代码

protected override void OnManipulationBoundaryFeedback(ManipulationBoundaryFeedbackEventArgs e)
{
    Debug.WriteLine("OnManipulationBoundaryFeedback");
}

private void MyControl_ManipulationBoundaryFeedback(object sender, ManipulationBoundaryFeedbackEventArgs e)
{
    Debug.WriteLine("MyControl_ManipulationBoundaryFeedback");
}

输出如下

OnManipulationBoundaryFeedback

MyControl_ManipulationBoundaryFeedback

OnManipulationBoundaryFeedback

MyControl_ManipulationBoundaryFeedback

OnManipulationBoundaryFeedback

MyControl_ManipulationBoundaryFeedback

OnManipulationBoundaryFeedback

MyControl_ManipulationBoundaryFeedback

所以您可以看到 OnManipulationBoundaryFeedback 先启动,然后调用 ManipulationBoundaryFeedbackEvent 处理程序

【讨论】:

  • 这不起作用。我在原始描述中提到 ManipulationBoundaryFeedback 事件处理程序不会为 WindowsFormsHost 元素(或任何继承的元素)处理此问题,我在对 Enfyve 的 cmets 中再次提到这不起作用,我刚刚进行了快速测试项目只是为了确保我不会发疯。这绝对行不通。
  • 重写 OnManipulationBoundaryFeedback 与向 ManipulationBoundaryFeedbackEvent 添加事件处理程序不同。我知道它 100% 有效,因为今天我遇到了这个问题并像这样解决了这个问题。
  • 观看此视频以查看此代码是否有效vimeo.com/237103516
【解决方案2】:

您可以为整个系统关闭此行为:

打开注册表(run regedit command)并将HKEY_CURRENT_USER\Software\Microsoft\Wisp\TouchBouncing设置为0; 如果HKEY_CURRENT_USER\Software\Microsoft\Wisp\Touch 不存在Bouncing 项,则添加它(DWORD 类型,不是QWORD 或字符串)并将其值设置为0

但是,即使它解决了我的问题,这也不是一个好的方法。看看这个manipulationboundaryfeedback-does-not-work-in-webbrowser-in-wpf

【讨论】:

  • 不知道为什么有人为此给出了-1。这正是我们的信息亭应用程序所需要的。不需要hacky代码。感谢和其他人 - 支持这个!
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多