0

we have a WPF component (User Control) that's hosted in a Win Form through ElementHost. the WPF component is defined as the ElementHost's Child through

ElementHostControl.Child = wpfFrame

there are certain key bindings we want to pass in from the Win Form to WPF form. we are doing so through KeyBinding(). then we assign the keybinding to the WPFFrame.InputBindings.add(curBinding);

it's kind working with most key combinations although I didn't test all of them. but Ctrl+B, Shift+P etc. seems all working fine.

But I try Shift+(Left Arrow key), it's not working. what's interesting is when I try it in standalone WPF application then it's doing the job as expected.

I made sure the data flow through the exactly same code but why Shift+P works while Shift+ <- doesn't? now I set a breakpoint in the WPF Commend executed and run it from Win Form. I use key binding to trigger another command then use Ctrl+<- to trigger the problematic command it actually "sometimes" working. if I remove breakpoint and do Ctrl+<- then it never triggers the associated command.

I suspect it's an integration issue in between WPF and Win form since Shift+<- works in WPF itself.

any input is appreciated.

youkebb
  • 161
  • 1
  • 7
  • It might be a focus issue. If the keyboard focus is not on the WPF element then it probably isn't going to receive the key event. You may need to forward the key event using the `RaiseEvent` on the WPF element: http://stackoverflow.com/a/1646568/476048 – Berin Loritsch Mar 16 '17 at 00:55

1 Answers1

0

it's indeed a focusing issue. setting a break point and this line: var v = Keyboard.FocusedElement;

at runtime shows the focus was stolen by various elements. I need to hand pick couple of them and set Focusable="False" in XAML. issue fixed!

youkebb
  • 161
  • 1
  • 7