可移植类库中的资源名称

本文关键字:资源 类库 可移植 | 更新日期: 2023-09-27 17:56:56

我正在尝试从可移植的类库(从WP8应用程序引用)加载BitmapImages。我需要 tp 首先检查资源是否是程序集的一部分,如果不是,则回退到从应用程序目录加载它们。如果图像位于同一程序集中,则此方法可以正常工作,但当它们位于可移植类库中时

,则无法正常工作。

这是我用来获取可移植类库中所有资源名称的代码:

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();
        }
    }
}

可移植类库中的资源名称

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

但请注意,本文是关于从 PCL 读取文本内容,而不是图像。我尚未设法从另一个程序集加载作为嵌入资源存储在 PCL 中的位图。也不鼓励在 PCL 中存储特定于平台的内容(如位图),因为处理甚至加载它们的方式在很大程度上是特定于平台的。