简体   繁体   English

在Win Form中托管WPF时的主要绑定问题

[英]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. 我们有一个WPF组件(用户控件),该组件通过ElementHost托管在Win Form中。 the WPF component is defined as the ElementHost's Child through WPF组件通过以下方式定义为ElementHost的子级:

ElementHostControl.Child = wpfFrame ElementHostControl.Child = wpfFrame

there are certain key bindings we want to pass in from the Win Form to WPF form. 我们希望将某些键绑定从Win窗体传递到WPF窗体。 we are doing so through KeyBinding(). 我们是通过KeyBinding()实现的。 then we assign the keybinding to the WPFFrame.InputBindings.add(curBinding); 然后将键绑定分配给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. 但Ctrl + B,Shift + P等似乎都可以正常工作。

But I try Shift+(Left Arrow key), it's not working. 但是我尝试了Shift +(向左键),它不起作用。 what's interesting is when I try it in standalone WPF application then it's doing the job as expected. 有趣的是,当我在独立的WPF应用程序中尝试它时,它就按预期完成了工作。

I made sure the data flow through the exactly same code but why Shift+P works while Shift+ <- doesn't? 我确保数据流经完全相同的代码,但是为什么Shift + P可以工作而Shift + <-不能工作? now I set a breakpoint in the WPF Commend executed and run it from Win Form. 现在,我在执行的WPF Commend中设置一个断点,并从Win Form运行它。 I use key binding to trigger another command then use Ctrl+<- to trigger the problematic command it actually "sometimes" working. 我使用键绑定触发另一个命令,然后使用Ctrl + <-触发实际上“有时”起作用的有问题的命令。 if I remove breakpoint and do Ctrl+<- then it never triggers the associated command. 如果我删除断点并执行Ctrl + <-,则它永远不会触发关联的命令。

I suspect it's an integration issue in between WPF and Win form since Shift+<- works in WPF itself. 我怀疑这是WPF和Win窗体之间的集成问题,因为Shift + <-在WPF本身中起作用。

any input is appreciated. 任何输入表示赞赏。

it's indeed a focusing issue. 这确实是一个重点问题。 setting a break point and this line: var v = Keyboard.FocusedElement; 设置断点和该行: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. 我需要手工挑选其中几个,并在XAML中设置Focusable =“ False”。 issue fixed! 问题已解决!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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