【问题标题】:Searching/Listing WPF resource files?搜索/列出 WPF 资源文件?
【发布时间】:2011-10-26 16:26:09
【问题描述】:

有没有办法在 WPF 应用程序中搜索资源?

我在一个应用程序中添加了许多图像,并希望执行搜索,即MS*.jpg 等,这可能吗?

如果我可以创建一个所有资源的列表,那肯定也会有所帮助,但我不希望它花费太多性能(我会使其延迟加载)。

【问题讨论】:

    标签: wpf resources resource-files resource-file


    【解决方案1】:

    一旦你把它们都放在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

    【讨论】:

      猜你喜欢
      • 2010-12-18
      • 1970-01-01
      • 1970-01-01
      • 2019-12-17
      • 2016-12-28
      • 2016-03-01
      • 1970-01-01
      • 2012-03-03
      相关资源
      最近更新 更多