【发布时间】: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