Winform开发框架中如何使用DevExpress的内置图标资源

2020-01-05 10:06:44丽君

这次搜索就直接基于已有的集合ImageCollection进行搜索的了,不用再次读取程序集并依次分析它,速度提供不少的。

由于图表资源的处理是比较耗时的,我们把整个图标加载的类作为一个静态的对象缓存起来,这样下次使用直接从缓存里面拿,对应的资源也不用重新加载,更好的提高我们重用的效果了,体验更好了。


/// <summary>
 /// 图标库加载处理
 /// </summary>
 public class DXImageGalleryLoader
 {
  /// <summary>
  /// 图标字典类别集合
  /// </summary>
  public Dictionary<string, GalleryItem> ImageCollection { get; set; }
  /// <summary>
  /// 图标分类
  /// </summary>
  public List<string> Categories { get; set; }
  /// <summary>
  /// 图标集合
  /// </summary>
  public List<string> Collection { get; set; }
  /// <summary>
  /// 图标尺寸
  /// </summary>
  public List<string> Size { get; set; }

  /// <summary>
  /// 使用缓存处理,获得对象实例
  /// </summary>
  public static DXImageGalleryLoader Default
  {
   get
   {
    System.Reflection.MethodBase method = System.Reflection.MethodBase.GetCurrentMethod();
    string keyName = string.Format("{0}-{1}", method.DeclaringType.FullName, method.Name);

    var result = MemoryCacheHelper.GetCacheItem<DXImageGalleryLoader>(keyName,
      delegate () { return new DXImageGalleryLoader().LoadData(); },
      new TimeSpan(0, 30, 0));//30分钟过期
    return result;
   }
  }

以上代码通过


public static DXImageGalleryLoader Default

定义了一个静态的实例属性,这样这个DXImageGalleryLoader 实例只会在程序第一次使用的时候构建并加载图片资源,后续都是从缓存里面读取,提高响应速度的同时,也会记住上次的选择界面内容。

以上就是整个功能的处理思路,以及一步步的优化处理,以便实现功能展示的同时,也提高响应速度,最终界面就是我们开始的时候介绍的那样。