开发者

Application icon is missing in the taskbar during program start, if another application is active

开发者 https://www.devze.com 2022-12-28 13:26 出处:网络
I\'ve written a WPF application which has a custom (not the standard) icon. A Splashscreen is implemented too.

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 displa开发者_高级运维yed in the windows task bar.

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

Any ideas?


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.


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.


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消