开发者

Taskbar icon will not change once binary is installed

I have a WPF application in .net 3.5 sp1 where I change the main window icon periodically. I am seeing the taskbar icon change when running under the vs hosting process, when running directly from the bin/Debug开发者_如何学C or bin/Release folders, but not when the binary is installed and running from \Program Files! The titlebar icon of the window still changes correctly...

I'm setting the icon like this:

Uri imageSource = new Uri("pack://application:,,,/MyProject;component/Images/test.ico");
this.Icon = BitmapFrame.Create(imageSource);

Why isn't the taskbar icon changing?

I do have an ApplicationIcon set. This is what the taskbar icon is displaying instead of changing to what I set it to. According to msdn The ApplicationIcon is just a fallback in case this.Icon is not set.

I do not have the taskbar icon pinned.

The main window is not the startup window of the application. In fact, there is no startup window. The window is opened from a system tray icon.

The icons for the ApplicationIcon and test.ico mentioned above both have their compile action set to Resource.

The WiX installer is not doing anything special to the exe or icons. The exe is referenced like this:

<File Id="MyExe" Name="$(var.MyProject.TargetFileName)"
 Source="$(var.MyProject.TargetPath)" KeyPath="yes" Vital="yes" />

I'm currently looking at the AppUserModelID to see if this can solve this but it seems unnecessary to override Windows 7's default behavior in this manner. I have two shortcuts created by WiX. One in the start menu's programs folder and one in the start menu's startup folder.

Update 18Aug11:

Ok this is just odd, odd, odd.

I started trying to solve another annoyance, that my window was allowing taskbar pinning when I don't really want it to (this is default win7 taskbar glomming). So I set IsHostApp REG_BINARY 0000 manually via regedit under HKCR\Applications\MyEXEName.exe. To have the change take effect I had to update the shortcuts that reference the app (or I could have reinstalled). Lo and behold, next time I start up the app, not only does the pinning feature disappear, but the taskbar icon properly updates!!!

Can someone explain how this has solved the issue?


When Windows Installer creates shortcuts in the Start menu, it sets the icon of the shortcuts which point to Installer cache of icons. This feature is required for advertising, where the referenced file does not exist but still the correct icon should be shown. It also allows showing the correct icon to the application if its main .exe is removed (and you can run MSI repair to fix it).

Your application is started with shortcut from Startup folder, and the icon of the shortcut is used on the Taskbar. (And you have the main window: no matter how you show it, when app starts or only when you click app icon in the notification area; moreover you have to have a window to be able to get clicks from notification area icon.)

When you disabled pinning your app to the Taskbar, it ignores the icon set in the shortcut that started your application, and therefore icon on Taskbar updates when you change the window icon.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜