wpf 图像资源和 Visual Studio 2010 资源编辑器
我提出这个问题的动机实际上只是通过 ImageSource 的依赖属性指定要在用户控件中使用的图像。我遇到了一些涉及管理、访问和单元测试的痛点。
- 资源编辑器是用于维护应用程序图像的好工具吗?
- 将位图从编辑器转换为图像源的最佳方法是什么?
- 如何从编辑器中获取资源文件名?
My motivation for this question is really just to specify an image to be used in a user control via a dependency property for ImageSource. I'm hitting some pain points involving the management, access, and unit testing for this.
- Is the resource editor a good tool to use to maintain images for the application?
- What is the best way to translate the Bitmap from the editor to an ImageSource?
- How can I grab the resource Filename from the editor?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
不,资源编辑器不是一个很好的工具。
在 WPF 应用程序中,最好的方法是将所有图像放入“图像”目录中,并将每个图像标记为“资源”。然后您可以直接在图像控件和其他地方引用它们。
以下是精确的步骤:
现在,您可以在 XAML 中轻松引用图像:
或者在代码中:
您还可以在外部程序集中引用图像:
在代码中将是:
No, the resource editor is not a good tool for this.
In a WPF application the best way is to put all of your images in an "Images" directory and mark each one as a "Resource". Then you can reference them directly in Image controls and elsewhere.
Here are the precise steps:
Now you can reference your images easily in XAML:
Or in code:
You can also reference images in external assemblies:
Which in code would be: