发布后图标不起作用
我有一个简单的应用程序。单击按钮时,任务栏图标会发生变化。当我从 Visual Studio 运行此应用程序时,一切正常,但是当我发布 WPF 应用程序时,任务栏图标不起作用(没有)。
构建操作设置为“嵌入资源/始终复制”,我也测试了“资源”,但它不起作用。
var iconUri = new Uri("pack://application:,,,/images/internet_connection.ico", UriKind.RelativeOrAbsolute);
this.Icon = BitmapFrame.Create(iconUri);
框架左上角的图标发生变化,但任务栏中的图标没有变化。
有人可以帮我吗?
@编辑,
感谢@Pavel 的评论,我让它正常工作。但现在仍然存在一个问题:
当我在 Visual Studio 中运行它时,我这样做:
var iconUri = UriHelper.GetUri(this.GetType(), "images/local_network.ico");
this.Icon = BitmapFrame.Create(iconUri);
图标发生了变化。但对于发布的版本来说,它并没有改变。
@@编辑,
好的,这是我按下按钮时的代码:
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 运行时:任务栏中的图标发生变化,覆盖层起作用,应用程序右上角的图标发生变化。
构建后运行 exe:任务栏中的图标不会改变,覆盖层有效,应用程序右上角的图标发生变化。
谁能解释一下吗?
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.
Can anyone help me please ?
@Edit,
I got it to work thanks to @Pavel's comment. But now one problem remains:
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.
@@Edit,
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 };
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.
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 ?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我认为这条线适合你(你忘记了......;组件/......):
用于图标使用
i think this line works for you (you have forgot the ...;component/....):
for the icon use
尝试在“资源”中设置构建操作并使用助手:
Try to set build action in 'Resource' and use a helper: