private Brush GetBackground(FavoriteModuleItem item) { Random r = new Random(item.ModuleID + (int)DateTime.Now.Ticks); return (new SolidColorBrush(Color.FromRgb((byte)r.Next(100, 255), (byte)r.Next(100, 255), (byte)r.Next(100, 255)))); }
private void CreateFavoriteModuleItems() { try { mListFavoriteItems.Clear(); mListTopFavoriteItems.Clear(); List <FavoriteModuleItem> listItems = new List <FavoriteModuleItem>(); for (int i = 0; i < mListModuleInfos.Count; i++) { var info = mListModuleInfos[i]; var usages = mListUsageInfos.Where(u => u.AppID == info.AppID && u.ModuleID == info.ModuleID); int count = usages.Count(); if (count <= 0) { continue; } FavoriteModuleItem item = new FavoriteModuleItem(); item.CurrentApp = CurrentApp; item.AppID = info.AppID; item.ModuleID = info.ModuleID; item.Name = info.Title; item.Title = CurrentApp.GetLanguageInfo(string.Format("FO{0}", info.ModuleID), info.Title); string strTip = string.Empty; strTip += string.Format("{0}:{1}\r\n", CurrentApp.GetLanguageInfo("1206001", "Title"), item.Title); strTip += string.Format("{0}:{1}", CurrentApp.GetLanguageInfo("1206002", "Count"), count); item.Tip = strTip; item.Icon = GetAppIcon(info); item.Background = GetBackground(item); item.UseCount = count; item.ModuleInfo = info; listItems.Add(item); } listItems = listItems.OrderByDescending(i => i.UseCount).ToList(); int maxNum = 5; var propertyValue = mListPropertyValues.FirstOrDefault(p => p.PropertyID == WIDGET_PROPERTY_ID_MAXMOUDLENUM); if (propertyValue != null) { string strValue = propertyValue.Value01; int intValue; if (int.TryParse(strValue, out intValue) && intValue > 0) { maxNum = intValue; } } for (int i = 0; i < listItems.Count; i++) { var item = listItems[i]; mListFavoriteItems.Add(item); if (i < maxNum) { mListTopFavoriteItems.Add(item); } } } catch (Exception ex) { ShowException(ex.Message); } }