WPF应用程序焦点不稳定

发布于 2024-09-08 21:08:20 字数 703 浏览 3 评论 0原文

如果我在使用 WPF 时遇到问题,那么它总是与焦点管理有关。 在某些情况下,我的应用程序完全失去焦点,因此另一个应用程序获得焦点,而我的应用程序进入后台。这种情况主要发生在我的应用程序中的某些窗口被关闭的情况下。 这是 WPF 的已知问题吗?其他人也有类似的问题吗?

我已经为此打开了另一个线程,但没有人可以帮忙看看,可能说得有点太详细了。因此,这是简短的版本。

更新

我似乎找到了一个简单的技巧,有助于防止我在 其他线程。如果您遇到同样的问题,请尝试它是否对您有帮助。如果您有一个解释,则有悬赏...

我将这篇文章保留几天,可能有人有很好的一般输入WPF 焦点问题。可能我不明白它背后的逻辑,但在我理解之前,这在我看来确实是 WPF 中最糟糕的部分(在我看来,这是一个非常棒的产品)。如果我必须告诉别人我过去几年在 WPF 中遇到的问题,那就是:Focusmgmt、Focusmgmt,以及再一次 Focusmgmt。

If I have problems with WPF, then it always concerns the Focus-Management. There are cases, my App loses totally focus so that another application gains the focus and my app goes in the background. This happens mainly if some windows in my app will be closed.
Is this a known problem of WPF. Does someone else has similar problems?

I already opened another thread to this, but no one could help, maybe it was a little to detailed. Therefore this here is the short version.

UPDATE

It seems that I have found a simple hack that helps prevent the behavior I describe in the other thread. If you have the same problem, try if it helps you. If you have an explanation, there is a bounty open for...

I leave this post open for a few days, may be someone has a good general input to the WPF-focus problematic. Probably I don't understand the logic behind it, but until I will understand, this is IMO really the worst part of WPF (what IMO is a really fantastic product). If I have to tell someone with what I had problems the last years within WPF, it would be: Focusmgmt, Focusmgmt, and one time more Focusmgmt.

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

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

发布评论

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

评论(2

轮廓§ 2024-09-15 21:08:20

为了使整个应用程序失去焦点,请确保在显示所有窗口之前设置“Owner”属性。

对于在应用程序内失去焦点,通常当您没有想到的某些控件正在获取但没有显示任何内容(例如用于布局的一些随机 StackPanel 或 Grid)时,通常会发生这种情况,您必须寻找这些控件并添加 Focusable =“假”

For losing focus for the entire app make sure you set the Owner property on all windows before you show them.

For losing focus inside the app, usually this happens when some control you didn't think off is getting but not showing anything (for example some random StackPanel or Grid used for layout), you have to hunt those down and add Focusable="false"

七度光 2024-09-15 21:08:20

+1因为我在我的申请中也遇到了类似的问题。我正在开发一个类似 VS 的应用程序(用户可以添加(从工具箱)并在画布中配置控件),并且在执行各种命令(如删除等)后,焦点会神秘地丢失。我必须使用 Canvas.Focus()< /code> 显式地重置焦点,但这有时也不起作用。

+1 As I have also faced similar issues in my application. I am working on a VS like application(user can add(from toolbox) and configure controls in a Canvas) and focus is lost mysteriously after various commnads are executed like Delete etc. I have to use Canvas.Focus() explicitly to reset the focus and that too doesn't work sometimes.

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