在WPF应用程序中嵌入图标 [英] Embed Icon in WPF application

查看:184
本文介绍了在WPF应用程序中嵌入图标的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在两种情况下在我的应用程序中使用了一个图标。

I am using an icon in my application in two situations.


  1. 在XAML中使用DynamicResource作为Button的图像。

  2. 在C#中NotifyIcon

  1. In XAML as an Image for the Button using DynamicResource.
  2. In C# as NotifyIcon

this.notifyIcon.Icon = new SystemDrawing.Icon(..//..// Shutdown.ico);

this.notifyIcon.Icon = new SystemDrawing.Icon("..//..//Shutdown.ico" );

我的问题是如果删除应用程序无效的图像。如何将图像与exe文件绑定,以便应用程序只能使用exe文件运行?

My problem is if I delete the image the application not working. How can I bind the image with the exe file so that the application can run only with the exe file?

推荐答案

添加图标将项目作为资源(不是嵌入式资源,存在差异),然后使用

Add the icon to the project as a Resource (not Embedded Resource, there is a difference), then access it with

using(Stream stream = Application.GetResourceStream(new Uri("/Shutdown.ico")).Stream)
{
    this.notifyIcon.Icon = new SystemDrawing.Icon(stream);
}

你也应该能够在你的XAML中使用它,我只是不记得怎么回事。

You should also then be able to use it in your XAML too, I just can't remember how yet.

详情请见此处: http://msdn.microsoft.com/en-us/library/aa970494.aspx

注意:我没有在此处包含任何错误检查。在使用它之前,您应该确保检查流以查看它是否为空。

Note: I have not included any error checking here. You should probably make sure you check the stream to see if it is null before using it.

这篇关于在WPF应用程序中嵌入图标的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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