private void OnStatisticListSelectionChanged() { if (this.statisticNameSelectedItems == null || this.statisticNameSelectedItems.Count == 0) { return; } if (this.statisticNameSelectedItems.Count == 0 || this.statisticNameSelectedItems.Contains(StatisticsViewModel.DefaultStatText)) { this.LoadDefaultList(); } else { this.sortByList = this.statisticNameSelectedItems.Select(o => StatisticHelper.FromDisplayText(o.ToString())).ToList(); var newPages = new List <StatValueViewModel>(this.sortByList.Count); foreach (var stat in this.sortByList) { var newPage = new StatValueViewModel(StatisticHelper.GetDisplayText(stat)); var statList = this.Settings.Statistics.Select(st => st[stat]).Distinct().ToList(); statList.Sort((o1, o2) => StatisticComparer.Default.Compare(o1, o2)); newPage.StatisticValues = statList; newPage.PropertyChanged += this.newPage_PropertyChanged; newPages.Add(newPage); } this.Pages = newPages; this.SelectedPage = newPages[0]; } }
private void newPage_PropertyChanged(object sender, PropertyChangedEventArgs e) { if (e.PropertyName != "SelectedValue") { return; } var model = (StatValueViewModel)sender; var index = this.pages.IndexOf(model); var stats = new List <KeyValuePair <Statistic, object> >(index + 1); for (var i = 0; i < this.pages.Count; i++) { var selectedValue = this.pages[i].SelectedValue; if (selectedValue != null) { stats.Add(new KeyValuePair <Statistic, object>(this.sortByList[i], selectedValue)); } } if (stats.Count == 0) { this.ValueHeader = "Value"; this.StatisticList = this.GetDefaultList(); return; } var moduleList = this.Settings.Statistics.Where(st => this.HasAllValues(st, stats)).ToArray(); var statList = new List <StatDisplay>(); if (moduleList.Length == 0) { var statDisplay = new StatDisplay( StatisticHelper.GetDisplayText(Statistic.MatchCount), "0", StatisticHelper.GetDescription(Statistic.MatchCount)); statList.Add(statDisplay); } else { foreach (var stat in this.GetStatDisplayList()) { var statDisplay = new StatDisplay( StatisticHelper.GetDisplayText(stat), this.GetAverageValue(moduleList, stat), StatisticHelper.GetDescription(stat)); statList.Add(statDisplay); } } this.ValueHeader = "Average Value"; this.StatisticList = statList; }