WPF 中托管的 Windows 窗体用户控件 - 如何捕获离开事件?

发布于 2024-08-31 17:07:51 字数 832 浏览 5 评论 0原文

在我的 WPF 应用程序中,我将自定义 Windows 窗体用户控件与其他 wpf 控件一起托管。我的自定义用户控件使用 WindowsFormsHost 控件托管在 wpf 中。此自定义用户控件包含(可以说是父控件)其他自定义 win 表单控件(子控件)。子控件可以是单个控件或复合控件。

当用户从父自定义用户控件中的最后一个子用户控件导航到 wpf 用户控件时,如何捕获子控件上的离开事件?

根据 MSDN (http://msdn.microsoft.com/en-us/ Library/ms751797.aspx) 在以下情况下不支持离开事件:

当发生以下焦点更改时,不会引发 Enter 和 Leave 事件:

1. From inside to outside a WindowsFormsHost control.
2. From outside to inside a WindowsFormsHost control.
3. Outside a WindowsFormsHost control.
4. From a Windows Forms control hosted in a WindowsFormsHost control to an ElementHost control hosted inside the same WindowsFormsHost.

情况 1 和 2 正是我所遇到的问题。你有什么办法解决这个问题吗?一些解决方法或任何东西值得赞赏:)

最好的祝福,

OKB

In my WPF application I'm hosting a custom Windows Form User Control together with other wpf controls. My custom user control is hosted in wpf using a WindowsFormsHost control. This custom user control contains (the parent so to speak) other custom win form controls (children controls). The children controls can be single or composite controls.

How can I capture the leave event on a child control when the user navigates from the last child user control in the parent custom user control to a wpf user control?

According to MSDN (http://msdn.microsoft.com/en-us/library/ms751797.aspx) the leave event is not supported in following scenarios:

Enter and Leave events are not raised when the following focus changes occur:

1. From inside to outside a WindowsFormsHost control.
2. From outside to inside a WindowsFormsHost control.
3. Outside a WindowsFormsHost control.
4. From a Windows Forms control hosted in a WindowsFormsHost control to an ElementHost control hosted inside the same WindowsFormsHost.

Scenario 1 and 2 is exactly what I struggle with. Do you have any solution to this problem? Some workaround or anything is appreciated:)

Best Regards,

OKB

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

童话 2024-09-07 17:07:51

看起来您已经回答了自己的问题:不支持(即不可能)。

这可能是 WPF 和 Windows 窗体使用的窗口托管不同的结果 - 我确信该平台会支持它(如果可以的话)。

It looks like you have already answered your own question: it isn't supported (i.e. not possible).

This is likely a result of the difference in window hosting used by WPF and Windows Forms - and I am sure the platform would support it if it could.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文