发布后图标不起作用 [英] Icons don't work after publish

查看:142
本文介绍了发布后图标不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个简单的应用程序。单击按钮时,tasbar图标会发生变化。当我从visual studio运行这个应用程序时,一切正常,但是当我发布WPF应用程序时,任务栏图标不起作用(没有)。

I have a simple application. When you click a button, the tasbar icon changes. When I Run this app from visual studio, everything works fine, but when I publish the WPF app, the taskbar Icon does not work (there is none).

构建动作设置为嵌入式资源/总是复制,我也测试了资源但它不起作用。

The build action is set to "embedded resource/copy always", I have tested "Resource" as well but it doesn't work.

var iconUri = new Uri("pack://application:,,,/images/internet_connection.ico", UriKind.RelativeOrAbsolute);
        this.Icon = BitmapFrame.Create(iconUri);

框架左上角的图标发生变化,但任务栏中的图标没有变化。

the icon in the top left corner of the frame changes, but the one in the taskbar doesn't.

有人可以帮我吗?

@Edit,

感谢@ Pavel的评论,我得到了它的工作。但现在仍然存在一个问题:

I got it to work thanks to @Pavel's comment. But now one problem remains:

当我在visual studio中运行它时,我这样做:

When I run it in visual studio, and I do this:

var iconUri = UriHelper.GetUri(this.GetType(), "images/local_network.ico");
        this.Icon = BitmapFrame.Create(iconUri);

图标发生变化。但是对于已发布的版本,它不会改变。

The Icon changes. But with the published version, it doens't change.

@@编辑,

好的这是当我按下按钮时的代码:

Ok so this is my code when I press a button:

  var iconUri = UriHelper.GetUri(this.GetType(), "images/internet_connection.ico");
        this.Icon = BitmapFrame.Create(iconUri);
        mNotifyIcon = new NotifyIcon
        {
            BalloonTipText = "The app has been minimised. Click the tray icon to show.",
            BalloonTipTitle = "The App",
            Text = "The App",
            Icon = BitmapFrame.Create(iconUri)
        };

        BitmapImage image = new BitmapImage();
        image.BeginInit();
        image.UriSource = UriHelper.GetUri(this.GetType(), "images/internet_connection.png");
        image.EndInit();
        TaskbarItemInfo = new System.Windows.Shell.TaskbarItemInfo() { Overlay = image };

它做什么:
从VS运行时:任务栏中的图标发生变化,覆盖层工作,应用程序顶角的图标发生变化。

what does it do: When running from VS: the icon in the taskbar changes, the overlay works, the icon in the top corner of the application changes.

构建运行exe后:任务栏中的图标不会改变,覆盖层工作,应用程序右上角的图标发生变化。

After build running the exe: the icon in the taskbar DOES NOT change, the overlay works, the icon in the top corner of the application changes.

任何人都可以解释一下吗?

Can anyone explain this ?

推荐答案

我认为这条线适合你(你忘了......;组件/....):

i think this line works for you (you have forgot the ...;component/....):

var iconUri = new Uri("pack://application:,,,/YourProjectName;component/images/internet_connection.ico", UriKind.RelativeOrAbsolute);

图标使用

Build Action = Resource
Copy to OutputDirectory = Do not copy

这篇关于发布后图标不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆