WPF:如何从 DLL 资源文件设置图像源?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/18237481/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-13 09:26:25  来源:igfitidea点击:

WPF: How can I set image source from DLL resource file?

wpfxaml

提问by Andrey Bushman

How can I set image source from DLL resource file?

如何从 DLL 资源文件设置图像源?

<Image Source="res/png_32.png" Width="Auto" Height="Auto">

It works fine, but my image are located as resource in the DLL file. How can I get it?

它工作正常,但我的图像作为资源位于 DLL 文件中。我怎么才能得到它?

Thank you.

谢谢你。

采纳答案by Reed Copsey

You would handle this via a Pack URI:

您将通过Pack URI处理此问题:

<Image Source="pack://application:,,,/TheDLLName;component/res/png_32.png" Width="Auto" Height="Auto">