Cefsharp: WPF WindowsFormsHost Touch Screen not working

Created on 14 Oct 2016  路  22Comments  路  Source: cefsharp/CefSharp

  • What version of the product are you using?

    • 1銆丯uget 53

    • 2銆乥uild 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 锛欳efSharp.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

faq-able! wpf

Most helpful comment

@mortalV
@softwaretirol

  • Using the open source 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
    ```c#
    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

All 22 comments

@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

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鈥榮 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.

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.

Has anyone solved this problem?

OK! I solved it.

How did you solved it?

@mortalV
@softwaretirol

  • Using the open source 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
    ```c#
    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

@ccnucheng You are a god amongst men. Great job discovering the fix, and amazing community dedication for sharing it in such detail.

Maybe you can use the WPF control. It fix in https://github.com/cefsharp/CefSharp/pull/2745

Was this page helpful?
0 / 5 - 0 ratings

Related issues

nico87 picture nico87  路  46Comments

hpposch picture hpposch  路  27Comments

MIvoylov picture MIvoylov  路  26Comments

amaitland picture amaitland  路  29Comments

amaitland picture amaitland  路  43Comments