存储用作 WPF 应用程序图标的图像的推荐方法是什么?
我正在 WPF 中创建一个非常标准的业务应用程序。 我需要在工具栏和菜单项以及其他一些地方使用图标。 我想知道三个(可能相互关联的)事情的答案:
- 我应该使用什么格式的图像? 首次代币发行? 巴布亚新几内亚? JPG? 动图?
- 如何在 VS2008 项目中存储图像? 作为磁盘上的文件? 在 RESX 文件中? 在资源字典中? (如果在资源字典中,那么在字典“编译”之前它们是否也必须位于磁盘上?)
- 一旦文件正确存储在我的项目中,如何最好地引用它们?
谢谢!
更新:
我接受了克里斯·尼科尔的回答,但我想澄清一下我做了什么记录。
- 我在项目中创建了一个名为
Images
的文件夹。 - 我将图像放入此文件夹中,并确保它们的构建操作是“资源”。
- 我创建了一个名为
Images.xaml
的ResourceDictionary
XAML 文件。 在其中,我为每个文件创建了一个条目,格式如下:BitmapImage x:Key="FooIcon" Source="Images\foo.png"
。 - 然后,我根据需要以通常的方式引用了这个
ResourceDictionary
。
我主要关心的是生成的图像作为资源添加到 DLL 中,并且可以通过 WPF 的资源系统访问它们。
I am creating a pretty standard business application in WPF. I need to use icons for the toolbars and menu items, and in a few other places. I'd like to know the answers to three (likely interrelated) things:
- What format should I use for the images? ICO? PNG? JPG? GIF?
- How do I store the images in my VS2008 project? As files on disk? In a RESX file? In a resource dictionary? (If in a resource dictionary, do they then also have to be on disk before the dictionary is "compiled"?)
- Once the files are stored appropriately in my project, how best to reference them?
Thanks!
Update:
I accepted Chris Nicol's answer, but I want to clarify what I did for the record.
- I created a folder in my project called
Images
. - I put my images into this folder, and made sure that their build action was "Resource".
- I created a
ResourceDictionary
XAML file calledImages.xaml
. Inside of this, I created an entry for each file, in the following format:BitmapImage x:Key="FooIcon" Source="Images\foo.png"
. - I then referenced this
ResourceDictionary
in the usual way as needed.
My primary concern was that the resulting images be added to the DLL as resources and that they be accessible through WPF's Resource system.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
格式 - 根据经验,我会说 .PNG,尽管 .ICO 可能会满足您的需求,具体取决于原始图形的来源和大小。
存储 - 它们将是项目中的资源,很可能在文件夹结构下创建。 然后可以通过 XAML 访问它们。
参考 - 这取决于您的应用程序的架构。 在最基本的解决方案中,您将有一个样式来设置工具栏的图像源属性(实现取决于您的控件)。 每个工具栏都会实现一个样式资源。
希望有帮助!
Format - I would say .PNG from experience, though .ICO may suit your needs depending on the source and size of your original graphic.
Storage - They would be resources in the project, most likely created under a folder structure. They can then be accessed through the XAML.
Referencing - It depends on the architecture of your application. In the most basic solution you would have a style that would set the image source property of your toolbar (implementation depends on your control). Each toolbar would implement a style resource.
Hope that helps!