搜索/列出 WPF 资源文件?

发布于 2024-12-11 18:53:01 字数 145 浏览 0 评论 0原文

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

我已向应用程序添加了许多图像并想要执行搜索,即 MS*.jpg 等,这可能吗?

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

Is there a way to search a WPF application for resources?

I have added many images to an app and want to perform search i.e. MS*.jpg etc., Is this possible?

If I could create a list of all the resources, that would surely be helpful as well, but I don't want it to cost to much performance (I will make it lazy loaded tho).

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

手心的温暖 2024-12-18 18:53:01

一旦将它们全部放在 IEnumerable 下,搜索工作就会容易得多。

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

答案取自此处

Once you have them all under an IEnumerable<string> the search job is hell of a lot easier.

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

Answer taken from here

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文