是否可以列出添加到程序集并标记为资源(未嵌入)的所有文件。
我尝试过 GetManifestResourceNames 方法。它仅适用于嵌入式资源。但我需要将标记为资源的文件,以便使用uri来访问该文件,例如 pack:// application:,,, / ApplicationName; component / Resources / logo.png < / p>
感谢
答案 0 :(得分:5)
你可以像这样访问它:
var image = new BitmapImage(new Uri("pack://application:,,,/ApplicationName;component/Resources/logo.png", UriKind.Absolute))
<强> [编辑] 强>
您可以通过调用此方法列出所有这些:
public static string[] GetResourceNames()
{
var asm = Assembly.GetEntryAssembly();
string resName = asm.GetName().Name + ".g.resources";
using (var stream = asm.GetManifestResourceStream(resName))
using (var reader = new System.Resources.ResourceReader(stream))
{
return reader.Cast<DictionaryEntry>().Select(entry => (string)entry.Key).ToArray();
}
}