CefSharp icon indicating copy to clipboard operation
CefSharp copied to clipboard

WPF WindowsFormsHost Touch Screen not working

Open Jovan-Cheng opened this issue 10 years ago • 23 comments

  • What version of the product are you using?
    • 1、Nuget 53
    • 2、build from a branch 49.0.2623
  • What architecture x86 or x64?
    • x64
  • On what operating system?
    • Win7
  • Are you using WinForms, WPF or OffScreen?
    • WPF
  • What steps will reproduce the problem?
    • Reference :CefSharp.dll CefSharp.Core.dll CefSharp.Winform.dll
    • Use 'WindowsFormsHost' control in my wpf program
    • Create 'ChromiumWebBrowser' and add it to 'WindowsFormsHost'
    • After running, you can display the page, but no Touch effect
  • What is the expected output? What do you see instead?
    • Can touch scroll and pinch

Jovan-Cheng avatar Oct 14 '16 06:10 Jovan-Cheng

@ccnucheng Does the Touch Screen work when using the native WinForms implementation? You can test it using https://github.com/cefsharp/CefSharp.MinimalExample

amaitland avatar Oct 14 '16 07:10 amaitland

@amaitland - Touch Screen is work when using the native WinForms implementation. - Touch Screen is work when using WindowsFormsHost in WPF with Win10

Jovan-Cheng avatar Oct 14 '16 08:10 Jovan-Cheng

Two things to try

  • Firstly make sure your app has the relevant compatibility entries in the app.manifest. https://github.com/cefsharp/CefSharp.MinimalExample/blob/master/CefSharp.MinimalExample.Wpf/app.manifest#L37
  • Secondly you can attempt to run the message loop on your UI thread, this often fixes a lot of random problems see https://github.com/cefsharp/CefSharp.MinimalExample/commit/15c4a7a7845452c190f6e44c5b7db41ccb504601

The fact it works in Win 10 likely means there isn't a whole lot that can be done. CefSharp is just a wrapper around CEF after all.

amaitland avatar Oct 14 '16 08:10 amaitland

@amaitland

  • Still can not Touch, when after the App.manifest file modified, The CefSettings parameter is already the same as in the example

Jovan-Cheng avatar Oct 14 '16 10:10 Jovan-Cheng

The CefSettings parameter is already the same as in the example

I find that unlikely, the browser doesn't function without some sort of message loop processing. Check again.

amaitland avatar Oct 14 '16 10:10 amaitland

@amaitland

I find that unlikely, the browser doesn't function without some sort of message loop processing. Check again.

Although still can not touch, but still thank you very mach!

Jovan-Cheng avatar Oct 15 '16 02:10 Jovan-Cheng

So you've got the message loop running on the dispatcher? Have you tested on different hardware with Windows 7?

amaitland avatar Oct 15 '16 02:10 amaitland

Yes,I addCef.DoMessageLoopWork() in window‘s Loaded event,and use DispatcherTimer execute it,and test on defferent machine with windows 7!It's still can't touch

Jovan-Cheng avatar Oct 15 '16 03:10 Jovan-Cheng

You can try CefGlue or ChromiumFx, see if you have better luck with a different framework.

amaitland avatar Oct 15 '16 07:10 amaitland

Adding "touch-events=enabled" to command line arguments, when starting CEF, fixed simillar issue I had.

szymonmalok avatar Oct 16 '16 21:10 szymonmalok

@szymonmalok Yes,I have added the parameters ,but still can not touch the scrren!

Jovan-Cheng avatar Oct 17 '16 06:10 Jovan-Cheng

We have the same problem. Hosting the WPF Control in a WindowsFormsHost but Touch Events dont work on Windows 7. On Windows 8 or 10 , there is no problem.

softwaretirol avatar Oct 25 '16 13:10 softwaretirol

@softwaretirol Did you solve it?

Jovan-Cheng avatar Oct 28 '16 09:10 Jovan-Cheng

No - we still have the problem.

softwaretirol avatar Oct 28 '16 09:10 softwaretirol

touch Touching Event is initiated, but does not work as expected, If you happen to click on it so 50 times, sometimes an Event is working, but It's random.

toprezr avatar Oct 28 '16 11:10 toprezr

Has anyone solved this problem?

Jovan-Cheng avatar Nov 03 '16 07:11 Jovan-Cheng

OK! I solved it.

Jovan-Cheng avatar Nov 24 '16 07:11 Jovan-Cheng

How did you solved it?

mortalV avatar Nov 24 '16 08:11 mortalV

@mortalV
@softwaretirol

  • Using the open source WmTouchDevice
    • https://github.com/jaytwo/WmTouchDevice
  • Call MessageTouchDevice.RegisterTouchWindow(IntPtr hWnd) in your Window's Loaded event
    • System.IntPtr hWnd = new System.Windows.Interop.WindowInteropHelper(this).Handle;
    • WmTouchDevice.MessageTouchDevice.RegisterTouchWindow(hWnd);
  • Add the CustomControl(WPF) in your project,and inherited from WindowsformsHost
public class CefWindowsFormsHost : WindowsFormsHost
{
	static CefWindowsFormsHost()
	{
		DefaultStyleKeyProperty.OverrideMetadata(typeof(CefWindowsFormsHost), new FrameworkPropertyMetadata(typeof(CefWindowsFormsHost)));
	}
	
	protected override IntPtr WndProc(IntPtr hwnd, int msg, IntPtr wParam, IntPtr lParam, ref bool handled)
	{
		WmTouchDevice.MessageTouchDevice.WndProc(System.Windows.Window.GetWindow(this), msg, wParam, lParam, ref handled);
		return base.WndProc(hwnd, msg, wParam, lParam, ref handled);
	}
}
  • Use this Custom WFH(CefWindowsFormsHost) replace the System.Windows.Forms.Integration.WindowsFormsHost

Jovan-Cheng avatar Nov 28 '16 02:11 Jovan-Cheng

Great, sounds like there is a valid workaround 👍 Closing

amaitland avatar Jan 10 '17 01:01 amaitland