static void InsertSample(GalleryItemCollection items, int count) { for (int i = 0; i < count; i++) { items.Add(new GalleryItem(null, null, string.Concat("DX Sample ", ++Index), string.Concat("The Drag&Drop gallery items example."), -1, -1, null, string.Empty, true, false)); } }
/// <summary> /// 根据条件获取集合 /// </summary> /// <returns></returns> public Dictionary <string, GalleryItemCollection> Search(List <string> collection, List <string> categories, List <string> size, string fileName = "") { Dictionary <string, GalleryItemCollection> dict = new Dictionary <string, GalleryItemCollection>(); GalleryItemCollection list = new GalleryItemCollection(); foreach (var key in ImageCollection.Keys) { //使用正则表达式获取图标文件名中的集合、类别、大小等信息 string reg = @"(?<collection>\S*?)/(?<category>\S*?)/(?<name>\S*)"; var collectionItem = CRegex.GetText(key, reg, "collection"); var categoryItem = CRegex.GetText(key, reg, "category"); string sizeReg = @"_(?<size>\S*)\."; var sizeItem = CRegex.GetText(key, sizeReg, "size"); //如果是查询处理,把记录放到查询结果里面 if (!string.IsNullOrEmpty(fileName)) { if (key.Contains(fileName)) { list.Add(ImageCollection[key]); } dict["查询结果"] = list; } else { //如果是集合和列表中包含的,把它们按类别添加到字典里面 if (collection.Contains(collectionItem) && categories.Contains(categoryItem) && size.Contains(sizeItem)) { if (!dict.ContainsKey(categoryItem)) { GalleryItemCollection cateList = new GalleryItemCollection(); cateList.Add(ImageCollection[key]); dict[categoryItem] = cateList; } else { GalleryItemCollection cateList = dict[categoryItem]; cateList.Add(ImageCollection[key]); } } } } return(dict); }