1

我需要检查是否存在嵌入式资源。在 WPF 中,这相对容易,但在 WP7 中,我得到一个 MissingManifestResourceException

有效的 WPF 代码是:

public static IEnumerable<object> GetResourcePaths(Assembly assembly) { 
        var culture = System.Threading.Thread.CurrentThread.CurrentCulture; 
        //var resourceName = assembly.GetName().Name + ".g"; 
        var assemblyName = assembly.FullName.Split(',')[0]; 
        var resourceName = assemblyName + ".g"; 
        var resourceManager = new ResourceManager(assemblyName, assembly); 

        try { 
            var resourceSet = resourceManager.GetResourceSet(culture, true, true); 

            foreach (System.Collections.DictionaryEntry resource in resourceSet) { 
                yield return resource.Key; 
            } 
        } finally { 
            resourceManager.ReleaseAllResources(); 
        } 
    } 

我尝试用下面的代码替换它,这导致了异常(在第 9 行)。有没有办法在 Silverlight / WP7 中做到这一点?

public static IEnumerable<object> GetResourcePaths(Assembly assembly) { 
            var culture = System.Threading.Thread.CurrentThread.CurrentCulture; 
            //var resourceName = assembly.GetName().Name + ".g"; 
            var assemblyName = assembly.FullName.Split(',')[0]; 
            var resourceName = assemblyName + ".g"; 
            var resourceManager = new ResourceManager(assemblyName, assembly); 

            try { 
                var resourceSet = resourceManager.GetResourceSet(culture, true, true); 

                foreach (System.Collections.DictionaryEntry resource in resourceSet) { 
                    yield return resource.Key; 
                } 
            } finally { 
                resourceManager.ReleaseAllResources(); 
            } 
        } 
4

1 回答 1

0

上一个问题的答案:WP7:图像集合似乎表明您可能需要在调用GetResourceSet之前获取流:

var NOT_USED = rm.GetStream("app.xaml"); // without getting a stream, next statement doesn't work - bug?

听起来有点hacky,但如果它有效;)

于 2011-04-11T14:08:15.397 回答