如何使用 WindowsFormHost 在 WPF 中聚焦
我有一个简单的设置:
<StackPanel>
<TextBox Text="wpf1" PreviewLostKeyboardFocus="TextBox_PreviewLostKeyboardFocus" />
<TextBox Text="wpf2" PreviewLostKeyboardFocus="TextBox_PreviewLostKeyboardFocus" />
<WindowsFormsHost>
<wf:TextBox Text="winforms" />
</WindowsFormsHost>
</StackPanel>
private void TextBox_PreviewLostKeyboardFocus(object sender, KeyboardFocusChangedEventArgs e)
{
e.Handled = true;
}
三个文本框、两个 WPF 和一个 WinForm。我无法在我想要的两个 WPF 文本框之间移动焦点,但我可以将焦点移动到 WinForm 文本框。从 WPF 文本框移动到 WinForm 文本框时,甚至不会触发 PreviewLostKeyboardFocus
事件。关于为什么以及如何解决这个问题的任何线索?
编辑
我注意到,当焦点再次离开 WindowsFormsHost 时,首先触发 WindowsFormsHost.PreviewGotKeyboardFocus
。太奇怪了。也许这是一个错误?
I have this simple setup:
<StackPanel>
<TextBox Text="wpf1" PreviewLostKeyboardFocus="TextBox_PreviewLostKeyboardFocus" />
<TextBox Text="wpf2" PreviewLostKeyboardFocus="TextBox_PreviewLostKeyboardFocus" />
<WindowsFormsHost>
<wf:TextBox Text="winforms" />
</WindowsFormsHost>
</StackPanel>
private void TextBox_PreviewLostKeyboardFocus(object sender, KeyboardFocusChangedEventArgs e)
{
e.Handled = true;
}
Three textboxes, two WPF and one WinForm. I can't move focus between the two WPF-Textboxes which I desired but I can move focus to the WinForm-Textbox. The event PreviewLostKeyboardFocus
does not even triggered when moving from a WPF-Textbox to a WinForm-Textbox. Any clues to why and how this could be solved?
EDIT
I've noticed that WindowsFormsHost.PreviewGotKeyboardFocus
is triggered first when focus is leaving the WindowsFormsHost again. Thats odd. Maybe it's a bug?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论