UIElement GenPolyline(object selected, WaveFileReader wfr, double widthScale, double height, int scale) { double width = wfr.TotalTime.TotalSeconds * widthScale; Polyline shape = new Polyline { StrokeThickness = 1.0, Tag = selected, Height = height, Width = width, Stroke = new LinearGradientBrush { GradientStops = { new GradientStop { Color = Colors.DarkGray, Offset = 0 }, new GradientStop { Color = Colors.Gray, Offset = 0.8 }, } }, }; for (int x = 0; ; x++) { double[] samples = wfr.ReadOneSample(); if (samples == null || samples.Length < 1) { break; } if (x % scale != 0) { continue; } double xx = x * shape.Width / wfr.Length; double yy = (samples[0] + 1.0) * height / 2.0; shape.Points.Add(new Point(xx, yy)); } return(shape); }