walterlv / BlogComments

3 stars 0 forks source link

wpf/2017/09/12/touch-not-work-in-wpf #117

Open utterances-bot opened 2 years ago

utterances-bot commented 2 years ago

WPF 程序无法触摸操作?我们一起来找原因和解决方法! - walterlv

WPF 程序可能出现各种各样的触摸失效的问题,这里进行了一些总结。

https://blog.walterlv.com/wpf/2017/09/12/touch-not-work-in-wpf.html

wutangyuan commented 2 years ago

水哥,我发现主窗体弹出模态弹出模态小弹窗之后,小弹窗之外的区域多指触碰,再点击小弹窗,有概率小窗体不触发触摸事件,这个问题好像不在以上的三个已知问题上。。

lindexi commented 2 years ago

@wutangyuan 没有遇到此问题,方便给个 demo 文件?

wutangyuan commented 2 years ago

@wutangyuan 没有遇到此问题,方便给个 demo 文件? 是一个很简单的样例,一个大窗体,点击按钮,ShowDialog出一个模态弹窗(模态窗体附一个小按钮,用于检测是否命中,也可以用snoop监听)。 主要的步骤:弹出模态弹窗之后,在大窗体多指触控,或者手指触控滑动,再立即点击模态弹窗,模态窗体有概率接受不了触控的事件(注意:鼠标是正常的)

dlgcy commented 1 year ago

http://dlgcy.com/wpf-touch-event-promote-to-touch-event-and-datagrid-touch-problem/ 帮忙看看误触问题的这个解决方法能简化吗?

heIIo1995 commented 1 year ago

@wutangyuan 你这个问题解决了吗 我程序也有这个bug

sczmzx commented 1 year ago

wpf能响应到笔的移动消息,但是按下事件无效,导致笔不能书写,这个是属于哪一类呢?

wutangyuan commented 10 months ago

@heIIo1995,我目前的修改方案是:自定义模态弹窗替换原生的showDialog来规避这个问题

lindexi commented 7 months ago

现在这几个问题都可以尝试更新到 dotnet core 版本或 .NET Framework 4.8 版本试试

wutangyuan commented 7 months ago

水哥,如何在应用内部判断是否存在触摸失效?通过Tablet.TabletDevices的个数,我发现在触摸失效的时候,是有设备个数的。。

lindexi commented 7 months ago

@wutangyuan 这么奇怪的呀,基本上的触摸失效都是取不到设备触摸数量。你可以试试 https://github.com/dotnet-campus/ManipulationDemo 工具在你的设备看,看看是否真的是触摸失效问题

wutangyuan commented 6 months ago

@wutangyuan 这么奇怪的呀,基本上的触摸失效都是取不到设备触摸数量。你可以试试 https://github.com/dotnet-campus/ManipulationDemo 工具在你的设备看,看看是否真的是触摸失效问题

我调试出来了,某些第三方应用使用了模拟触控,会导致WPF的置顶的窗体触摸失效,用了ManipulationDemo看了,是有触摸设备的,但是在AppDomain.CurrentDomain.FirstChanceException 抛出了异常, image 目前我是在异常堆栈里边信息判断如果是penimc的Penimc.IPimcManager2,重启应用来规避这个问题

lindexi commented 6 months ago

@wutangyuan 6

lindexi commented 6 months ago

@wutangyuan 你看能否开启 WM_Pointer 消息,看看在 WM_Pointer 里的错误是什么

开启方法:

打开 App.xaml.cs 文件,在构造函数添加下面代码

        public App()
        {
            AppContext.SetSwitch("Switch.System.Windows.Input.Stylus.EnablePointerSupport", true);
        }
lindexi commented 6 months ago

我想看看 https://github.com/dotnet/wpf/issues/8435 这个问题是不是也是被模拟设备

wutangyuan commented 6 months ago
AppContext.SetSwitch("Switch.System.Windows.Input.Stylus.EnablePointerSupport", true);

@lindexi 我添加 AppContext.SetSwitch("Switch.System.Windows.Input.Stylus.EnablePointerSupport", true); 是正常的,没有异常信息和错误。 本来一开始我也是想通过设置开始pointer 规避以上触摸失效的问题,但是Pointer开启后,修改屏幕的dpi,会触摸偏移,所以就放弃该方案了。还是用回实时触摸,通过FirstChanceException 返回的堆栈重启应用,去规避这个问题

lindexi commented 6 months ago

@wutangyuan 那看来之前别人给我报的问题和你遇到的不是相同的一个问题呀

开启 Pointer 的触摸偏移问题,可以已经被修了,可以试试 https://www.nuget.org/packages/dotnetCampus.WPF.Resource/6.0.4-alpha07-test06 这个包。使用方法可以编辑 csproj 文件,添加如下代码

  <ItemGroup>
    <PackageReference Include="dotnetCampus.WPF.Resource" Version="6.0.4-alpha07-test06" />
  </ItemGroup>

  <ItemGroup>
    <Reference Include="$(CustomWpfAssetsFolder)lib\net6.0\*.dll" />
    <ReferenceCopyLocalPaths Include="$(CustomWpfAssetsFolder)lib\net6.0\*.dll" />
  </ItemGroup>