【发布时间】:2011-10-26 16:26:09
【问题描述】:
有没有办法在 WPF 应用程序中搜索资源?
我在一个应用程序中添加了许多图像,并希望执行搜索,即MS*.jpg 等,这可能吗?
如果我可以创建一个所有资源的列表,那肯定也会有所帮助,但我不希望它花费太多性能(我会使其延迟加载)。
【问题讨论】:
标签: wpf resources resource-files resource-file
有没有办法在 WPF 应用程序中搜索资源?
我在一个应用程序中添加了许多图像,并希望执行搜索,即MS*.jpg 等,这可能吗?
如果我可以创建一个所有资源的列表,那肯定也会有所帮助,但我不希望它花费太多性能(我会使其延迟加载)。
【问题讨论】:
标签: wpf resources resource-files resource-file
一旦你把它们都放在IEnumerable<string> 下,搜索工作就容易多了。
public static IEnumerable<object> GetResourcePaths()
{
var culture = System.Threading.Thread.CurrentThread.CurrentCulture;
var resourceName = CurrentAssembly.GetName().Name + ".g";
var resourceManager = new ResourceManager(resourceName, CurrentAssembly);
try
{
var resourceSet = resourceManager.GetResourceSet(culture, true, true);
foreach (DictionaryEntry resource in resourceSet)
{
yield return resource.Key;
}
}
finally
{
resourceManager.ReleaseAllResources();
}
}
答案来自here
【讨论】: