0

I have an application using cefSharp and some KeyGestures to open some forms. We were initially using the WPF ChromiumWebBrowser, but required the use of touch scrolling, which is not supported. As a result, we changed the control to the WinForms ChromiumWebBrowser inside a WindowsFormHost.

After the switch, KeyGestures bound to our RoutedCommands no longer fire.

After reviewing here, here, and here, I have tried several different solutions, but to no avail.

As per the above, when the window is deactivated, then activated the KeyGestures are routed appropriately (as discussed regarding breakpoints 'causing' the commands to work).

I have tried using the CommandManager.InvalidateRequerySuggested method on a timer or being called on loaded, after transfering focus to the window, after transfering forcus to another WPF control and after focusing the WindowsFormsHosts.

My command declaration is as follows:

            RoutedCommand ShowAdmin = new RoutedCommand();
            ShowAdmin.InputGestures.Add(new KeyGesture(Key.F1, ModifierKeys.Shift | ModifierKeys.Alt | ModifierKeys.Control));
            CommandBindings.Add(new CommandBinding(ShowAdmin, ShowAdminForm));

I essentially have two questions:

1) Why am I not receiving the command. Is it because the WinForms control doesn't 'bubble' the keypress events?

2) What can I do to capture the keygesture without resorting to opening another window, only to close it again

Thanks in advance for your questions, comments and answers!

Community
  • 1
  • 1
chaosaffe
  • 848
  • 9
  • 22

1 Answers1

0

If you implement IKeyboardHandler you should be handle custom key press combinations, that's probably your easiest and cleanest solution.

https://github.com/cefsharp/CefSharp/blob/master/CefSharp/IKeyboardHandler.cs

amaitland
  • 4,073
  • 3
  • 25
  • 63
  • While the workaround did solve the specified issue, it still doesn' address the OP's questions, and specifically does not deal with any touch gestures. – chaosaffe Apr 25 '15 at 03:09
  • It could be a couple of things, without looking into it further I can't provide an accurate answer. There are a lot of downsides to running a `WinForms` control within `WPF`, see http://blogs.msdn.com/b/scoberry/archive/2006/09/01/735844.aspx for just some of them. – amaitland Apr 25 '15 at 03:27
  • Also you didn't explicitly ask any questions about touch gestures, you simply said you required it and switched to the `WinForms` control. – amaitland Apr 25 '15 at 03:30
  • That is fair. And the issues are prevalent. The only reason for using the WinForm control is the lack of touch scroll with the WPF control... – chaosaffe Apr 25 '15 at 03:36
  • There is probably a way to support touch scrolling in the `WPF` control, would be a matter of interpreting the touch, getting the delta and sending it to the mouse wheel handler. https://github.com/cefsharp/CefSharp/blob/master/CefSharp.Wpf/ChromiumWebBrowser.cs#L1189 – amaitland Apr 25 '15 at 04:03
  • Could potentially translate something like http://matthamilton.net/touchscrolling-for-scrollviewer. Just an idea, no idea if it's practical. – amaitland Apr 25 '15 at 04:06
  • Actually http://blogs.msdn.com/b/llobo/archive/2009/12/07/wpf-touch-basics.aspx would be even better. – amaitland Apr 25 '15 at 04:08
  • Wow... I don't understand why that hasn't already been implemented in the CefSharp framwork! Thank you very much for your input asd solutions. As usual, I was overthinking it :) – chaosaffe Apr 25 '15 at 19:05
  • I've created https://github.com/cefsharp/CefSharp/issues/975 as a placeholder. Contributions most welcome :) – amaitland Apr 25 '15 at 22:45