1

我正在尝试从可运动的类库(从 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();
        }
    }
}
4

1 回答 1

2

看看这篇关于如何从 PCL 访问资源的文章: http ://www.irisclasson.com/2012/11/01/example-windows-store-app-portable-class-library-how-to-access-和-使用-pcl-资源/

但请注意,本文是关于从 PCL 读取文本内容,而不是图像。我还没有设法从另一个程序集加载作为嵌入式资源存储在 PCL 中的位图。也不鼓励在 PCL 中存储位图等特定于平台的内容,因为您处理甚至加载它们的方式非常特定于平台。

于 2013-02-03T14:40:45.113 回答