private void variety_PropertyChanged(object sender, PropertyChangedEventArgs e) { if (e.PropertyName == "SegmentFrequencyDistribution") { Segment curSeg = null; if (SelectedSegment != null) { curSeg = SelectedSegment.DomainSegment; } _segments.ReplaceAll(DomainVariety.SegmentFrequencyDistribution.ObservedSamples.Select(seg => new VarietySegmentViewModel(this, seg))); MaxSegmentProbability = _segments.Select(seg => seg.Probability).Concat(0).Max(); if (curSeg != null) { SelectedSegment = _segments.FirstOrDefault(vm => vm.DomainSegment.Equals(curSeg)); } } }
private void PopulateSegments() { var segmentComparer = new SegmentComparer(); var categoryComparer = new SegmentCategoryComparer(); _busyService.ShowBusyIndicatorUntilFinishDrawing(); using (_domainSegments.BulkUpdate()) using (_segments.BulkUpdate()) { _domainSegments.Clear(); _segments.Clear(); foreach (Segment segment in _projectService.Project.Varieties .SelectMany(v => v.SyllablePositionSegmentFrequencyDistributions[DomainSyllablePosition].ObservedSamples) .Distinct().OrderBy(s => s.Category(), categoryComparer).ThenBy(s => s, segmentComparer)) { _domainSegments.Add(segment); _segments.Add(new SegmentViewModel(segment)); } } _categories.ReplaceAll(_segments.GroupBy(s => s.DomainSegment.Category()).OrderBy(g => g.Key, categoryComparer).Select(g => new SegmentCategoryViewModel(g.Key, g))); HasSegments = _segments.Count > 0; }