我正在尝试从可运动的类库(从 WP8 应用程序引用)加载 BitmapImages。我需要先检查资源是否是程序集的一部分,如果不是,则回退到从应用程序目录加载它们。如果图像在同一个程序集中,这很好用,但当它们在可移植类库中时就不行了。
这是我用来获取可移植类库中所有资源名称的代码:
public static IEnumerable<object> GetResourcePaths(Assembly assembly) {
var culture = System.Threading.Thread.CurrentThread.CurrentCulture;
var mrn = assembly.GetManifestResourceNames();
// mrn contains all of my image resources
foreach (var resource in mrn) {
var rm = new ResourceManager(resource.Replace(".resources", ""), assembly);
//When I call either of the next two lines, I get a 'System.Resources.MissingManifestResourceException'
var NOT_USED = rm.GetStream("app.xaml"); // without getting a stream, next statement doesn't work - bug?
var rs = rm.GetResourceSet(Thread.CurrentThread.CurrentUICulture, false, true);
var enumerator = rs.GetEnumerator();
while (enumerator.MoveNext()){
yield return enumerator.Key.ToString();
}
}
}