protected override void OnApplyTemplate() { base.OnApplyTemplate(); this.PathFigure0 = GetTemplateChild("PathFigure0") as PathFigure; this.SubPath = GetTemplateChild("SubPath") as Path; title = GetTemplateChild("Title") as TextBlock; Y0 = GetTemplateChild("Y0") as TextBlock; Y1 = GetTemplateChild("Y1") as TextBlock; Y2 = GetTemplateChild("Y2") as TextBlock; Y3 = GetTemplateChild("Y3") as TextBlock; Y4 = GetTemplateChild("Y4") as TextBlock; X0 = GetTemplateChild("X0") as TextBlock; X1 = GetTemplateChild("X1") as TextBlock; X2 = GetTemplateChild("X2") as TextBlock; X3 = GetTemplateChild("X3") as TextBlock; X4 = GetTemplateChild("X4") as TextBlock; if (Values0 == null || Values0.Count < 1) { return; } double bottom; double top; double labelStep; if (Values1 == null || Values1.Count < 1) { SubPath.Visibility = Visibility.Collapsed; var max = Values0.Max(); var min = Values0.Min(); if (max == min) { min -= min * 0.1; max += max * 0.1; } bottom = min - (max - min) * 0.1; top = max + (max - min) * 0.1; bottom = bottom < Minimum ? Minimum : bottom; top = top > Maximum ? Maximum : top; var center = (max + min) / 2; labelStep = (top - bottom) / 4; } else { SubPath.Visibility = Visibility.Visible; var max = Math.Max(Values0.Max(), Values1.Max()); var min = Math.Min(Values0.Min(), Values1.Min()); if (max == min) { min -= min * 0.1; max += max * 0.1; } bottom = min - (max - min) * 0.1; top = max + (max - min) * 0.1; bottom = bottom < Minimum ? Minimum : bottom; top = top > Maximum ? Maximum : top; var center = (max + min) / 2; labelStep = (top - bottom) / 4; } var pathFigure1 = ((((SubPath.Data as GeometryGroup).Children[0] as PathGeometry).Figures as PathFigureCollection)[0] as PathFigure); PathFigure0.Segments.Clear(); pathFigure1.Segments.Clear(); title.Text = Title; Y0.Text = bottom.ToString("0.0") + FormatDecoration; Y1.Text = (bottom + labelStep).ToString("0.0") + FormatDecoration; Y2.Text = (bottom + 2 * labelStep).ToString("0.0") + FormatDecoration; Y3.Text = (bottom + 3 * labelStep).ToString("0.0") + FormatDecoration; Y4.Text = (bottom + 4 * labelStep).ToString("0.0") + FormatDecoration; if (!XText.IsNullorEmpty()) { var xTexts = XText.Split(','); X0.Text = xTexts[0]; X1.Text = xTexts[1]; X2.Text = xTexts[2]; X3.Text = xTexts[3]; X4.Text = xTexts[4]; } var actualMin = bottom; var actualMax = bottom + 4 * labelStep; var length = actualMax - actualMin; var step = 512 / (Values0.Count + 1); var actaulStart = GRAPH_ACTUALSTART - ((Values0[0] - actualMin) / length) * GRAPH_ACTUALHEIGHT; PathFigure0.StartPoint = new Windows.Foundation.Point(step, actaulStart); for (int i = 0; i < Values0.Count; i++) { var actaulY = GRAPH_ACTUALSTART - ((Values0[i] - actualMin) / length) * GRAPH_ACTUALHEIGHT; PathFigure0.Segments.Add(new LineSegment { Point = new Windows.Foundation.Point(step * (i + 1), actaulY) }); } if (Values1 != null && Values1.Count > 0) { var step1 = 512 / (Values1.Count + 1); var actaulStart1 = GRAPH_ACTUALSTART - ((Values1[0] - actualMin) / length) * GRAPH_ACTUALHEIGHT; pathFigure1.StartPoint = new Windows.Foundation.Point(step1, actaulStart1); for (int i = 0; i < Values1.Count; i++) { var actaulY = GRAPH_ACTUALSTART - ((Values1[i] - actualMin) / length) * GRAPH_ACTUALHEIGHT; pathFigure1.Segments.Add(new LineSegment { Point = new Windows.Foundation.Point(step1 * (i + 1), actaulY) }); } } }