简体   繁体   中英

key binding issues when hosting WPF in Win Form

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.

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!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM