如果另一个应用程序处于活动状态,则程序启动期间任务栏中会缺少应用程序图标

发布于 2024-08-30 12:15:52 字数 211 浏览 3 评论 0原文

我编写了一个具有自定义(非标准)图标的 WPF 应用程序。还实现了闪屏。

如果我启动应用程序并等待其加载,图标将正确显示。

但是,如果我在显示启动屏幕之前启动应用程序并切换到另一个应用程序(例如 Outlook),则该图标不会显示在 Windows 任务栏中。

如果我通过 alt+tab 切换到我的应用程序,该图标会直接出现。

有什么想法吗?

I've written a WPF application which has a custom (not the standard) icon. A Splashscreen is implemented too.

The icon is correctly displayed if I start the application and wait until it is loaded.

But, if I start my application and switch to another application (e.g. Outlook) before the my splash screen is shown, the icon is not displayed in the windows task bar.

The icon appears directly if I switch via alt+tab to my application.

Any ideas?

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

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

发布评论

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

评论(3

蓝眼泪 2024-09-06 12:15:52

我对用另一种语言(PowerBuilder,而不是基于 .Net 的语言)编写的程序也遇到了同样的问题,该程序的行为完全相同。如果它影响的不仅仅是 WPF,则一定是 Windows 问题。因此必须有一种方法来解决这个问题。

如果“我的”任务栏项目未处于活动状态,则框架可能会以错误的方式请求该项目。

将焦点设置回应用程序时,任务栏图标会重新出现。

一个粗略的解决方案是这样做(伪代码):

application.Hide();
application.Show()

另一个解决方案(伪代码):

application.SetRedraw(False);
application.Show();
application.SetRedraw(True);

但这会产生令人讨厌的闪烁。仅“重新激活”或“重绘”工具栏的解决方案会更好!

问题的原因(在我的非 WPF 情况下)是程序在主窗口的构造函数完成之前显示了 UI。即在所有初始化代码完成之前强制重绘/显示窗口。这可能会导致 Windows 认为该窗口不是应用程序,而是启动屏幕的“对话框”,并且不分配任务栏项目。当我设法删除过早显示主 GUI 的代码时,问题就消失了。

I had the same problem with a program written in another language (PowerBuilder, and not the .Net bases one) that behaves exactly the same. Must be a Windows problem if it affects more than just WPF. So there must be a way to work-around this.

Maybe the framework ask for "my" taskbar item in the wrong way if it isn't active.

The taskbar icon reappears when setting focus back to the application.

A crude solution is to do this (Pseudo code):

application.Hide();
application.Show()

Another solution (Pseudo code):

application.SetRedraw(False);
application.Show();
application.SetRedraw(True);

But this creates a nasty blinking. A solution that just "reactivates" or "redraws" toolbar would be better!

The cause of the problem (in my non WPF case) is that the program shows a UI before the constructor of the main window is complete. I.e. a force redraw/show of the window before all initialization code is done. This probably causes Windows to think the window isn't an application but rather a "dialog" of the splash screen and not assigning a taskbar item. When I managed to remove the code that prematurely showed the main GUI the problem went away.

池木 2024-09-06 12:15:52

我在使用 Winforms 应用程序时遇到了完全相同的问题。我找到的解决方案也可能对您的 WPF 应用程序有所帮​​助。

只需确保窗口的标题在最后一刻之前不发生更改即可。在 Winforms 中,我将 Text = "blahblah" 行从 Form_load 事件中移出,移至 Form1_Shown 事件中,现在隐藏任务栏图标问题已经消失。

I had exactly the same problem with a Winforms app. The solution I found may help your WPF app too.

Simply make sure the window's title isn't changed, until the last possible moment. In Winforms, I moved the Text = "blahblah" line out of the Form_load event, and into the Form1_Shown event, and now that hidden taskbar icon problem has vanished.

独自唱情﹋歌 2024-09-06 12:15:52

我在某些操作系统上看到类似的问题,但不是全部。当我切换程序时,任务栏中的图标将更改为默认应用程序(“空窗口”)。这似乎是 WPF 本身的问题,而不是你的程序的问题。

I see a similar problem on some OS but not all. When I switch program, the icon I have in my taskbar is changed to the default application onw (the "empty window"). It seems to be a problem with WPF itself, not anything with your program per say.

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