【问题标题】:Chromium/CefSharp touch events are not being firedChromium/CefSharp 触摸事件没有被触发
【发布时间】:2018-04-08 11:59:57
【问题描述】:

我在 wpf 应用程序中有一个模型视图,它使用 chromium 版本 41 托管 url。 url 是具有两个文本输入的 html 页面,每个文本输入都有一个指令(角度 1.5),它将“touchstart”事件绑定到每个输入。 当我在 chrome 中打开 Url(没有 chromium 包装器)时,我可以看到触摸事件正在工作,当我在 chromium 下打开 url 时,触摸事件没有被触发。

有人以前见过这个问题吗?会不会和铬版有关?

我的 xaml:

    <Window x:Class="CefSharpTest.MainWindow"
            xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
            xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
            xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
            xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
            xmlns:local="clr-namespace:CefSharpTest"
            xmlns:cefSharp="clr-namespace:CefSharp.Wpf;assembly=CefSharp.Wpf"
            mc:Ignorable="d"
            Title="MainWindow" Height="350" Width="525">
        <Grid>
            <cefSharp:ChromiumWebBrowser x:Name="MyBrowser" Address="http://localhost:9090/test.html"></cefSharp:ChromiumWebBrowser>
        </Grid>
    </Window>

我的 xaml 代码:

using System.Windows;
    using CefSharp;

    namespace CefSharpTest
    {
        /// <summary>
        /// Interaction logic for MainWindow.xaml
        /// </summary>
        public partial class MainWindow : Window
        {
            public MainWindow()
            {
                InitializeComponent();
                MyBrowser.FrameLoadEnd += MyBrowser_FrameLoadEnd;
            }

            private void MyBrowser_FrameLoadEnd(object sender, CefSharp.FrameLoadEndEventArgs e)
            {
                MyBrowser.ShowDevTools();
            }
        }
    }

我的html:

<html>
    <head>
        <script src="https://ajax.aspnetcdn.com/ajax/jQuery/jquery-3.3.1.min.js"></script>
    </head>
    <body>
        <script>
            $(document).ready(function(){
                $("#txtTest").on("touchstart", function(e){
                    console.log("touch");
                });
                $("#txtTest").on("keydown", function(e){
                    console.log("key down");
                });
            });
        </script>
        <input id="txtTest" type="text" width="250px" height="250px" />
    </body>
</html>

谢谢

【问题讨论】:

  • WPF版本不支持触摸屏,可以在WPF中托管WinForms版本。版本 63 是支持的最新版本。
  • 感谢您的回复,我在 winform 上试过了,效果很好。有没有办法让它在 wpf 上工作?我知道 cef 有 Tuch Down 事件并且它正在工作,但我需要在特定输入的 javascript 中触摸启动
  • 您可以使用 WPF 中托管的 WinForms 版本,这是我的建议。有关 WPF 问题,请参阅 github.com/cefsharp/CefSharp/issues/228

标签: chromium cefsharp


【解决方案1】:

我找到了解决办法:

在我注册到 TouchDown 事件的 chromium 上,在 touch down 事件中我执行了异步脚本,将位置 (x,y) 相对于浏览器发送到客户端。 在 javascript 函数中,我使用 document.elementFromPoint(x, y); 并且如果输入了元素:文本我正在处理触摸事件。

【讨论】:

    猜你喜欢
    • 2019-11-02
    • 2012-06-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多