本文整理汇总了C#中ObservableCollection.GroupBy方法的典型用法代码示例。如果您正苦于以下问题:C# ObservableCollection.GroupBy方法的具体用法?C# ObservableCollection.GroupBy怎么用?C# ObservableCollection.GroupBy使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ObservableCollection
的用法示例。
在下文中一共展示了ObservableCollection.GroupBy方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ListBindComboBox
public void ListBindComboBox(ObservableCollection<FLOW_MODELDEFINE_T> list)
{
ObservableCollection<FLOW_MODELDEFINE_T> systemCode = new ObservableCollection<FLOW_MODELDEFINE_T>();
var systemcode = list.GroupBy(s => s.SYSTEMCODE);
foreach (var item in systemcode)
{
systemCode.Add(item.FirstOrDefault() as FLOW_MODELDEFINE_T);
}
list.Insert(0, new FLOW_MODELDEFINE_T() { MODELCODE = "0", DESCRIPTION = "请选择......" });
MessageList.cbModelCode.ItemsSource = list;
MessageList.cbModelCode.SelectedIndex = 0;
systemCode.Insert(0, new FLOW_MODELDEFINE_T() { SYSTEMCODE = "0", SYSTEMNAME = "请选择......" });
MessageList.cbSystemCode.ItemsSource = systemCode;
MessageList.cbSystemCode.SelectedIndex = 0;
MessageList.appModel = list;
MessageList.appSystem = systemCode;
RuleList.cbSystemCode.ItemsSource = systemCode;
RuleList.cbModelCode.ItemsSource = list;
RuleList.cbSystemCode.SelectedIndex = 0;
RuleList.cbModelCode.SelectedIndex = 0;
RuleList.appSystem = systemCode;
RuleList.appModel = list;
triggerList.cbSystemCode.ItemsSource = systemCode;
triggerList.cbModelCode.ItemsSource = list;
triggerList.cbSystemCode.SelectedIndex = 0;
triggerList.cbModelCode.SelectedIndex = 0;
triggerList.appSystem = systemCode;
triggerList.appModel = list;
}
示例2: SearchRootNode
public SearchRootNode(string title, IList<SearchResultMatch> results)
{
this.Title = title;
this.resultNodes = new ObservableCollection<SearchResultNode>(results.Select(r => new SearchResultNode(r)));
this.fileNodes = new ObservableCollection<SearchFileNode>(resultNodes.GroupBy(r => r.FileName).Select(g => new SearchFileNode(g.Key, g.ToList())));
this.IsExpanded = true;
}
示例3: SearchRootNode
public SearchRootNode(string title, IList<SearchResultMatch> results)
{
this.Title = title;
this.resultNodes = new ObservableCollection<SearchResultNode>(results.Select(r => new SearchResultNode(r)));
this.fileNodes = new ObservableCollection<SearchFileNode>(
resultNodes.GroupBy(r => r.FileName)
.Select(g => new SearchFileNode(g.Key, g.ToList()))
);
this.projectNodes = new ObservableCollection<SearchProjectNode>(
resultNodes.GroupBy(r => SD.ProjectService.FindProjectContainingFile(r.FileName))
.Select(g => new SearchProjectNode(g.Key, g.OfType<SearchNode>().ToList()))
);
this.projectAndFileNodes = new ObservableCollection<SearchProjectNode>(
resultNodes.GroupBy(r => SD.ProjectService.FindProjectContainingFile(r.FileName))
.Select(g => new SearchProjectNode(g.Key, g.GroupBy(r => r.FileName).Select(g2 => new SearchFileNode(g2.Key, g2.ToList())).OfType<SearchNode>().ToList()))
);
this.IsExpanded = true;
}
示例4: SetPanoramaApps
protected void SetPanoramaApps(ObservableCollection<HubCrawlApp> apps)
{
var appGroups = apps.GroupBy(a => a.Group);
ObservableCollection<PanoramaGroup> appGroupCollection = new ObservableCollection<PanoramaGroup>();
foreach (var group in appGroups)
{
appGroupCollection.Add(new AppPanoramaGroup(group.Key, CollectionViewSource.GetDefaultView(group)));
PanoramaControl.SetBinding(HubCrawl.WPF.Controls.Panorama.ItemsSourceProperty, new Binding() { Source = appGroupCollection });
}
}
示例5: OnCustomersReceived
public void OnCustomersReceived(ObservableCollection<CustomerModel> customers)
{
Customers = customers;
IsEnabled = true;
IEnumerable<PiePointModel> piePoints = Customers.GroupBy(i => i.Country).Select(s => new PiePointModel()
{
Name = s.Key,
Amount = s.Count()
});
CountryRatioCollection = new ObservableCollection<PiePointModel>(piePoints);
}
示例6: ShowEventSynopsisReportCommandExecuted
private async void ShowEventSynopsisReportCommandExecuted()
{
var eventSynopsisView = new ForwardSynopsisDescriptionView();
var events = await _eventsDataUnit.EventsRepository.GetEventsForReportsAsync(x => !x.IsDeleted);
var allevents = new List<EventModel>(events.Select(x => new EventModel(x, true)));
var Events = new ObservableCollection<EventModel>(allevents);
var eventsGroups = new ObservableCollection<EventsGroup>(Events.GroupBy(p => p.Date)
.Where(x => x.Key.Date >= EventsFromDate.Date && x.Key.Date <= EventsToDate.Date)
.OrderBy(p => p.Key).Select(x => new EventsGroup(x.Key, new ObservableCollection<EventModel>(x))));
RadDocument document;
string[] values;
eventSynopsisView.GetRadDocumentAndValues(out document, out values, eventsGroups, EventsFromDate, EventsToDate);
PrintService.Export(document, values);
}
示例7: GetAlbumDetails
private ObservableCollection<Album> GetAlbumDetails(ObservableCollection<SongViewModel> songs)
{
var tracks = songs.GroupBy(s => s.Album).Select(t => t.First()).ToList();
ObservableCollection<Album> albums = new ObservableCollection<Album>();
foreach (SongViewModel song in tracks)
{
string upDir = Directory.GetParent(song.FilePath).FullName;
if (File.Exists(upDir + "\\cover.jpg"))
{
albums.Add(new Album(song.Album, upDir + "\\cover.jpg"));
}
else if(File.Exists(Directory.GetParent(upDir).FullName.ToString() + "\\cover.jpg"))
{
albums.Add(new Album(song.Album, upDir + "\\cover.jpg"));
}
}
return albums;
}
示例8: CreateDataSource
protected object CreateDataSource()
{
var avgFunc = FunctionLib.Avg();
var sumFunc = FunctionLib.Sum();
string[] date = new string[2];
//DateTime date = DateTime.Parse("0");
ObservableCollection<ReportViewModel> res = new ObservableCollection<ReportViewModel>();
var groupedBySymbolBenchMark = benchMark.GroupBy(s => s.Symbol);
var groupedBySymbolLive = live.GroupBy(s => s.Symbol);
decimal liveaEx = 0; decimal liveaEn = 0; string liveside = "Other"; int livesize = 0;
decimal pnl = 0; decimal slippage = -100;
string benchMarkSide = ""; string benchMarkAccount = ""; string liveAccount = "";// int liveNumSym = 0; int benchMarkNumSym = 0;
#region get the number of live and benchmark trades symbols
/*IEnumerable<AccountViewModel> noduplicates = live.Distinct(new SymbolComparer());
foreach (var product in noduplicates)
liveNumSym++;
IEnumerable<BenchMarkViewModel> bnoduplicates = benchMark.Distinct(new BenchMarkSymbolComparer());
foreach (var product in bnoduplicates)
benchMarkNumSym++;*/
#endregion
#region combine all data in live data
foreach (var group in groupedBySymbolLive)
{
var avgExit = FunctionLib.Delay(avgFunc, 1);
var avgEntry = FunctionLib.Delay(avgFunc, 1);
var sumSize = FunctionLib.Delay(sumFunc, 1);
var bMsumSize = FunctionLib.Delay(sumFunc, 1);
var bMavgEntry = FunctionLib.Delay(avgFunc, 1);
var bMavgExit = FunctionLib.Delay(avgFunc, 1);
int fisrtbmSide = 0;
int fisrtSide = 0; decimal benchMarkaEn = 0; int benchMarksize = 0; decimal benchMarkaEx = 0;
benchMarkSide = "";
#region get the ave price and sum size in the group
foreach (var liveData in group)
{
liveAccount = liveData.Account;
//date = DateTime.ParseExact(liveData.Timestamp.ToString(), "yyyyMMdd-HH:mm:ss.fff",System.Globalization.CultureInfo.InvariantCulture, DateTimeStyles.AssumeUniversal);
date = liveData.Timestamp.Split(new char[] { '-' });
if (fisrtSide == 0)
{
liveside = liveData.Side;
fisrtSide++;
}
if (liveside == "Short")
{
if (liveData.Side == "Long")
{
liveaEx = avgExit(liveData.Price);
}
else if (liveData.Side == "Short")
{
liveaEn = avgEntry(liveData.Price);
livesize = sumSize(liveData.Size);
}
}
if (liveside == "Long")
{
if (liveData.Side == "Short")
{
liveaEx = avgExit(liveData.Price);
}
else if (liveData.Side == "Long")
{
liveaEn = avgEntry(liveData.Price);
livesize = sumSize(liveData.Size);
}
}
}
#endregion
#region get pnl data
if (liveside == "Short")
{
pnl = -(liveaEn + liveaEx) * livesize;
}
if (liveside == "Long")
{
pnl = -(liveaEx + liveaEn) * livesize;
}
#endregion
#region join the benchMark data
// bool show = true;
foreach (var brenMarkGroup in groupedBySymbolBenchMark)
{
if (group.Key == brenMarkGroup.Key)
{
foreach (var brenchMarkData in brenMarkGroup)
{
benchMarkAccount = brenchMarkData.Account;
//.........这里部分代码省略.........
示例9: MainViewModel
public MainViewModel()
{
CommandList = new ObservableCollection<CommandViewModel>();
AddCommandCommand = new RelayCommand(()=>
{
var list = CommandList.Where(q => q.Name.StartsWith("Command")).ToList();
int maxNum = 0;
foreach (var cmd in list)
{
var numStr = cmd.Name.Replace("Command", "");
int result;
bool isConvert = int.TryParse(numStr,out result);
if (isConvert)
{
if(maxNum < result)
{
maxNum = result;
}
}
}
maxNum++;
var command = new CommandViewModel();
command.Name = "Command"+maxNum;
command.AddSuccessStateCommand.Execute(null);
this.CommandList.Add(command);
});
DeleteCommandCommand = new RelayCommand<CommandViewModel>(command =>
{
CommandList.Remove(command);
});
UpdateCortanaCommand = new RelayCommand(()=>
{
if (CommandList.GroupBy(q => q.Name).Where(w => w.Count() > 1).Count() > 0)
{
Messenger.Default.Send<string>("Commandの名前が重複しています","error");
return;
}
CortanaXmlGenerator generator = new CortanaXmlGenerator(CommandPrefix,Example);
foreach(var command in CommandList)
{
foreach(var state in command.StateList)
{
if(state is SuccessStateViewModel)
{
generator.AddCommandService(command.Name+"_"+state.Name,state.Example,
state.ListenFor.Replace("\r","").Split('\n'),
state.FeedBack,
voiceCommandServiceName);
}else if(state is ScriptStateViewModel)
{
generator.AddCommandService(command.Name + "_" + state.Name, state.Example,
state.ListenFor.Replace("\r", "").Split('\n'),
state.FeedBack,
voiceCommandServiceName);
}else if(state is ProtocolStateViewModel)
{
generator.AddCommandNavigate(command.Name + "_" + state.Name, state.Example,
state.ListenFor.Replace("\r", "").Split('\n'),
state.FeedBack,
voiceCommandServiceName);
}
}
if (command.StateList.GroupBy(q => q.Name).Where(w => w.Count() > 1).Count() > 0)
{
Messenger.Default.Send<string>(command.Name+"コマンドのstateの名前が重複しています", "error");
return;
}
}
Messenger.Default.Send<bool>(true, "updating");
var xml = generator.GenerateXml();
CurrentXml = xml;
//Debug.Write(xml);
OnRegisterVoiceCommand(xml);
Messenger.Default.Send<bool>(false, "updating");
});
OnRegisterVoiceCommand += e =>
{
};
ChangePassCodeCommand = new RelayCommand(() =>
{
this.PassCode = Guid.NewGuid().ToString();
});
UpdatePreviewCommand = new RelayCommand(() =>
{
PreviewCollection.Clear();
foreach(var command in CommandList)
{
if (command.StateList.Count > 0)
{
var preview = new CommandPreview(
//.........这里部分代码省略.........
示例10: ListBindTree
public void ListBindTree(ObservableCollection<FLOW_MODELDEFINE_T> list)
{
ObservableCollection<FLOW_MODELDEFINE_T> systemCode = new ObservableCollection<FLOW_MODELDEFINE_T>();
var systemcode = list.GroupBy(s => s.SYSTEMCODE);
foreach (var item in systemcode)
{
systemCode.Add(item.FirstOrDefault() as FLOW_MODELDEFINE_T);
}
items.Clear();
//创建流程树的根
foreach (FLOW_MODELDEFINE_T item in systemCode)
{
TreeItem item2 = new TreeItem() { ID = item.SYSTEMCODE, Name = item.SYSTEMNAME, LevelID = 2, ParentID = "" };
var childrens = from e in list
where e.SYSTEMCODE == item.SYSTEMCODE
select e;
foreach (FLOW_MODELDEFINE_T child in childrens)
{
TreeItem subItem = new TreeItem() { ID = child.MODELCODE, Name = child.DESCRIPTION, LevelID = 3, ParentID = item.SYSTEMCODE };
if (!string.IsNullOrEmpty(subItem.ID))
{
item2.Children.Add(subItem);
//treeList.Add(subItem);
}
}
items.Add(item2);
}
//绑定树控件
tvFlow.ItemsSource = items;
systemCode.Insert(0, new FLOW_MODELDEFINE_T() { SYSTEMCODE = "0", SYSTEMNAME = "请选择......" });
list.Insert(0, new FLOW_MODELDEFINE_T() { SYSTEMCODE = "0", MODELCODE = "0", DESCRIPTION = "请选择......" });
ucFlowlist.appSystem = systemCode;
ucFlowlist.appModel = list;
FlowSystemModel.appModel = list;
FlowSystemModel.appSystem = systemCode;
ucFlowlist.cbModelCode.ItemsSource = list;
ucFlowlist.cbModelCode.SelectedIndex = 0;
ucFlowlist.cbSystemCode.ItemsSource = systemCode;
ucFlowlist.cbSystemCode.SelectedIndex = 0;
}
示例11: InitializeExecuteOrderSummaryItems
public void InitializeExecuteOrderSummaryItems(ObservableCollection<Order> executedOrders, RangeType rangeType, int interval)
{
this.ExecuteOrderSummaryItems.Clear();
IEnumerable<IGrouping<InstrumentClient, Order>> query = executedOrders.GroupBy(P => P.Transaction.Instrument, P => P);
foreach (IGrouping<InstrumentClient, Order> group in query)
{
List<Order> instrumentOfOrders = group.ToList<Order>();
Order order = group.First();
ExecuteOrderSummaryItem summaryItem = this.AddInstrumentSummaryItem(order.Transaction.Instrument);
string rangeValue = string.Empty;
if (rangeType == RangeType.Time)
{
rangeValue = order.Transaction.ExecuteTime.Value.ToShortTimeString();
instrumentOfOrders.OrderBy(P => P.Transaction.ExecuteTime);
}
else
{
rangeValue = order.ExecutePrice;
instrumentOfOrders.OrderBy(P => P.ExecutePrice);
}
foreach (Order orderEntity in instrumentOfOrders)
{
ExecuteOrderSummaryItem rangeSummaryItem = this.AddRangeSummaryItem(summaryItem, orderEntity, rangeType, interval, rangeValue);
summaryItem.Update(rangeSummaryItem, true);
summaryItem.SetAvgPrice();
}
}
}
示例12: Refresh
private void Refresh()
{
try
{
Dictionary<string, int> dictionary = new Dictionary<string, int>();
Formats = new AsyncObservableCollection<NamedValue<int>>();
Cameras = new AsyncObservableCollection<NamedValue<int>>();
Sessions = new AsyncObservableCollection<NamedValue<int>>();
Summary = new AsyncObservableCollection<NamedValue<string>>();
if (!IsInDesignMode)
{
Apps = new ObservableCollection<DbEvents>(ServiceProvider.Database.GetApp(From, To));
Files = new ObservableCollection<DbFile>(ServiceProvider.Database.GetFiles(From, To));
dictionary.Add("Jpg",0);
dictionary.Add("Raw", 0);
dictionary.Add("Video", 0);
dictionary.Add("Other", 0);
foreach (var file in Files)
{
var item=new FileItem(file.File);
if (item.IsJpg)
dictionary["Jpg"]++;
else if (item.IsRaw)
{
dictionary["Raw"]++;
}
else if (item.IsMovie)
{
dictionary["Video"]++;
}
else
{
dictionary["Other"]++;
}
}
foreach (var i in dictionary)
{
if(i.Value>0)
Formats.Add(new NamedValue<int>(i.Key,i.Value));
}
dictionary.Clear();
foreach (DbFile file in Files)
{
if(!dictionary.ContainsKey(file.Camera))
dictionary.Add(file.Camera,0);
dictionary[file.Camera]++;
}
foreach (var i in dictionary)
{
Cameras.Add(new NamedValue<int>(i.Key, i.Value));
}
dictionary.Clear();
foreach (DbFile file in Files)
{
if (!dictionary.ContainsKey(file.Session))
dictionary.Add(file.Session, 0);
dictionary[file.Session]++;
}
foreach (var i in dictionary)
{
Sessions.Add(new NamedValue<int>(i.Key, i.Value));
}
Summary.Add(new NamedValue<string>("Total photos", Files.Count.ToString()));
Summary.Add(new NamedValue<string>("Total used session", Sessions.Count.ToString()));
Summary.Add(new NamedValue<string>("Total used cameras", Cameras.Count.ToString()));
if (Files.Count > 0)
{
Summary.Add(new NamedValue<string>("Most used apperture",
Files.GroupBy(x => x.F).OrderByDescending(x => x.Count()).First().Key));
Summary.Add(new NamedValue<string>("Most used exposure",
Files.GroupBy(x => x.E).OrderByDescending(x => x.Count()).First().Key));
Summary.Add(new NamedValue<string>("Most used ISO",
Files.GroupBy(x => x.Iso).OrderByDescending(x => x.Count()).First().Key));
}
}
}
catch (Exception ex)
{
Log.Error("", ex);
}
}