【问题标题】:Resource Names From Portable Class Library可移植类库中的资源名称
【发布时间】:2013-02-01 15:04:12
【问题描述】:

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

【问题讨论】:

    标签: c# .net windows-phone-8 windows-phone portable-class-library


    【解决方案1】:

    看看这篇关于如何从 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 中存储位图等特定于平台的内容,因为您处理甚至加载它们的方式非常特定于平台。

    【讨论】:

    • 我已经在加载文本资源没有问题,是位图导致问题。
    • 我明白了。在类似的情况下,我最终放弃并开始将图像作为内容加载。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-11-22
    • 1970-01-01
    • 2015-12-16
    • 1970-01-01
    • 2012-08-28
    • 1970-01-01
    相关资源
    最近更新 更多