WPF WindowsFormsHost Touch Screen not working
- 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,WPForOffScreen?- 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
@ccnucheng Does the Touch Screen work when using the native WinForms implementation? You can test it using https://github.com/cefsharp/CefSharp.MinimalExample
@amaitland - Touch Screen is work when using the native WinForms implementation. - Touch Screen is work when using WindowsFormsHost in WPF with Win10
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
UIthread, 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
- Still can not Touch, when after the App.manifest file modified, The CefSettings parameter is already the same as in the example
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
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!
So you've got the message loop running on the dispatcher? Have you tested on different hardware with Windows 7?
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
You can try CefGlue or ChromiumFx, see if you have better luck with a different framework.
Adding "touch-events=enabled" to command line arguments, when starting CEF, fixed simillar issue I had.
@szymonmalok Yes,I have added the parameters ,but still can not touch the scrren!
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 Did you solve it?
No - we still have the problem.
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.
Has anyone solved this problem?
OK! I solved it.
How did you solved it?
@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 = newSystem.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
Great, sounds like there is a valid workaround 👍 Closing