/// <summary> /// Handles setting up the custom numbering margin. /// </summary> /// <remarks>Handles being called more than once as it will only add margin if it doesn't exist yet.</remarks> /// <history> /// [Curtis_Beard] 04/08/2015 ADD: update RichTextBox to AvalonEdit /// </history> private void InitCustomMargin() { if (hasCustomMargin) { return; } var leftMargins = this.TextArea.LeftMargins; var dottedLine = new System.Windows.Shapes.Line { X1 = 0, Y1 = 0, X2 = 0, Y2 = 1, StrokeDashArray = { 0, 2 }, Stretch = System.Windows.Media.Stretch.Fill, StrokeThickness = 1, StrokeDashCap = System.Windows.Media.PenLineCap.Round, Margin = new System.Windows.Thickness(2, 0, 2, 0), Tag = dottedLineTag }; dottedLine.SetBinding( System.Windows.Shapes.Line.StrokeProperty, new System.Windows.Data.Binding("LineNumbersForeground") { Source = this } ); leftMargins.Insert(0, customMargin); leftMargins.Insert(1, dottedLine); customMargin.SetBinding(System.Windows.Controls.Control.ForegroundProperty, new System.Windows.Data.Binding("LineNumbersForeground") { Source = this }); customMargin.SetBinding(System.Windows.Controls.Control.BackgroundProperty, new System.Windows.Data.Binding("LineNumbersMatchForeground") { Source = this }); hasCustomMargin = true; }
/// <summary> /// Handles setting up the custom numbering margin. /// </summary> /// <remarks>Handles being called more than once as it will only add margin if it doesn't exist yet.</remarks> /// <history> /// [Curtis_Beard] 04/08/2015 ADD: update RichTextBox to AvalonEdit /// </history> private void InitCustomMargin() { if (hasCustomMargin) { return; } var leftMargins = this.TextArea.LeftMargins; var dottedLine = new System.Windows.Shapes.Line { X1 = 0, Y1 = 0, X2 = 0, Y2 = 1, StrokeDashArray = { 0, 2 }, Stretch = System.Windows.Media.Stretch.Fill, StrokeThickness = 1, StrokeDashCap = System.Windows.Media.PenLineCap.Round, Margin = new System.Windows.Thickness(2, 0, 2, 0), Tag = dottedLineTag }; dottedLine.SetBinding( System.Windows.Shapes.Line.StrokeProperty, new System.Windows.Data.Binding("LineNumbersForeground") { Source = this } ); leftMargins.Insert(0, customMargin); leftMargins.Insert(1, dottedLine); customMargin.SetBinding(System.Windows.Controls.Control.ForegroundProperty, new System.Windows.Data.Binding("LineNumbersForeground") { Source = this }); customMargin.SetBinding(System.Windows.Controls.Control.BackgroundProperty, new System.Windows.Data.Binding("LineNumbersMatchForeground") { Source = this }); hasCustomMargin = true; }
/// <summary> /// Updates this instance. /// </summary> private void Update() { double xAxisWidthStep = (int)this.ActualWidth / this.XAxis.MIntervalCount; double xAxisWidthPosition = xAxisWidthStep; int xminorCount = 0; int yminorCount = 0; if ((this.XAxis.MLabels.Count) == _xLines.Count) { for (int i = 0; i < this.XAxis.MLabels.Count; i++) { Line line = _xLines[i]; line.X1 = xAxisWidthPosition; line.X2 = xAxisWidthPosition; line.Y2 = (int)this.ActualHeight; if (i != (this.XAxis.MLabels.Count - 1)) { for (int a = 0; a < this.XAxis.MinorTicksCount; a++) { Line minorline = _xMinorLines[xminorCount]; minorline.X1 = this.XAxis.DataToPoint((this.XAxis.MStartValue + (this.XAxis.MInterval * i)) + ((this.XAxis.MInterval / (this.XAxis.MinorTicksCount + 1)) * (a + 1))); minorline.X2 = this.XAxis.DataToPoint((this.XAxis.MStartValue + (this.XAxis.MInterval * i)) + ((this.XAxis.MInterval / (this.XAxis.MinorTicksCount + 1)) * (a + 1))); minorline.Y1 = 0; minorline.Y2 = this.ActualHeight; xminorCount++; } } xAxisWidthPosition += xAxisWidthStep; } } else { if ((this.XAxis.MLabels.Count) > _xLines.Count) { int offset = (this.XAxis.MLabels.Count) - _xLines.Count; for (int j = 0; j < offset; j++) { Line line = new Line { X1 = 0, X2 = 0, Y2 = this.ActualHeight }; Binding styleBinding = new Binding { Path = new PropertyPath("CrossLineStyle"), Source = this.XAxis }; Binding showCrossLines = new Binding { Path = new PropertyPath("ShowCrossLines"), Source = this.XAxis, Converter = new BooleanToVisibilityConverter() }; line.SetBinding(Line.VisibilityProperty, showCrossLines); line.SetBinding(Line.StyleProperty, styleBinding); for (int a = 0; a < this.XAxis.MinorTicksCount; a++) { Line minorline = new Line(); Binding minorstyleBinding = new Binding { Path = new PropertyPath("MinorCrossLineStyle"), Source = this.XAxis }; minorline.SetBinding(Line.StyleProperty, minorstyleBinding); Binding minorshowCrossLines = new Binding { Path = new PropertyPath("ShowMinorCrossLines"), Source = this.XAxis }; minorshowCrossLines.Converter = new BooleanToVisibilityConverter(); minorline.SetBinding(Line.VisibilityProperty, minorshowCrossLines); minorline.X1 = this.XAxis.DataToPoint((this.XAxis.MStartValue + (this.XAxis.MInterval * j)) + ((this.XAxis.MInterval / (this.XAxis.MinorTicksCount + 1)) * (a + 1))); minorline.X2 = this.XAxis.DataToPoint((this.XAxis.MStartValue + (this.XAxis.MInterval * j)) + ((this.XAxis.MInterval / (this.XAxis.MinorTicksCount + 1)) * (a + 1))); minorline.Y1 = 0; minorline.Y2 = this.ActualHeight; this.Children.Add(minorline); _xMinorLines.Add(minorline); } _xLines.Add(line); this.Children.Add(line); } } else { int offset = _xLines.Count - (this.XAxis.MLabels.Count); for (int j = 0; j < offset; j++) { for (int a = 0; a < this.XAxis.MinorTicksCount; a++) { this.Children.Remove(_xMinorLines[_xMinorLines.Count - 1]); _xMinorLines.RemoveAt(_xMinorLines.Count - 1); } this.Children.Remove(_xLines[_xLines.Count - 1]); _xLines.RemoveAt(_xLines.Count - 1); } } for (int i = 0; i < this.XAxis.MLabels.Count; i++) { Line line = _xLines[i]; line.X1 = xAxisWidthPosition; line.X2 = xAxisWidthPosition; line.Y2 = this.ActualHeight; if (i != (this.XAxis.MLabels.Count - 1)) { for (int a = 0; a < this.XAxis.MinorTicksCount; a++) { Line minorline = _xMinorLines[xminorCount]; minorline.X1 = this.XAxis.DataToPoint((this.XAxis.MStartValue + (this.XAxis.MInterval * i)) + ((this.XAxis.MInterval / (this.XAxis.MinorTicksCount + 1)) * (a + 1))); minorline.X2 = this.XAxis.DataToPoint((this.XAxis.MStartValue + (this.XAxis.MInterval * i)) + ((this.XAxis.MInterval / (this.XAxis.MinorTicksCount + 1)) * (a + 1))); minorline.Y1 = 0; minorline.Y2 = this.ActualHeight; xminorCount++; } } xAxisWidthPosition += xAxisWidthStep; } } double yAxisHeightStep = (int)this.ActualHeight / this.YAxis.MIntervalCount; double yAxisHeightPosition = yAxisHeightStep; if (YAxis.MLabels.Count == _yLines.Count) { for (int i = 0; i < YAxis.MLabels.Count; i++) { Line line = _yLines[i]; line.X2 = this.ActualWidth; line.Y1 = yAxisHeightPosition; line.Y2 = yAxisHeightPosition; if (i != (this.YAxis.MLabels.Count - 1)) { for (int a = 0; a < this.YAxis.MinorTicksCount; a++) { Line minorline = _yMinorLines[yminorCount]; minorline.Y1 = this.YAxis.DataToPoint((this.YAxis.MStartValue + (this.YAxis.MInterval * i)) + ((this.YAxis.MInterval / (this.YAxis.MinorTicksCount + 1)) * (a + 1))); minorline.Y2 = this.YAxis.DataToPoint((this.YAxis.MStartValue + (this.YAxis.MInterval * i)) + ((this.YAxis.MInterval / (this.YAxis.MinorTicksCount + 1)) * (a + 1))); minorline.X1 = 0; minorline.X2 = this.ActualWidth; yminorCount++; } } yAxisHeightPosition += yAxisHeightStep; } } else { if ((this.YAxis.MLabels.Count) > _yLines.Count) { int offset = (this.YAxis.MLabels.Count) - _yLines.Count; for (int j = 0; j < offset; j++) { Line line = new Line(); line.X1 = 0; line.X2 = this.ActualWidth; line.Y1 = yAxisHeightPosition; line.Y2 = yAxisHeightPosition; Binding showCrossLines = new Binding { Path = new PropertyPath("ShowCrossLines"), Source = this.YAxis, Converter = new BooleanToVisibilityConverter() }; line.SetBinding(Line.VisibilityProperty, showCrossLines); Binding styleBinding = new Binding { Path = new PropertyPath("CrossLineStyle"), Source = this.YAxis }; line.SetBinding(Line.StyleProperty, styleBinding); for (int a = 0; a < this.YAxis.MinorTicksCount; a++) { Line minorline = new Line(); Binding minorstyleBinding = new Binding { Path = new PropertyPath("MinorCrossLineStyle"), Source = this.YAxis }; minorline.SetBinding(Line.StyleProperty, minorstyleBinding); Binding minorshowCrossLines = new Binding { Path = new PropertyPath("ShowMinorCrossLines"), Source = this.YAxis }; minorshowCrossLines.Converter = new BooleanToVisibilityConverter(); minorline.SetBinding(Line.VisibilityProperty, minorshowCrossLines); minorline.Y1 = this.YAxis.DataToPoint((this.YAxis.MStartValue + (this.YAxis.MInterval * j)) + ((this.YAxis.MInterval / (this.YAxis.MinorTicksCount + 1)) * (a + 1))); minorline.Y2 = this.YAxis.DataToPoint((this.YAxis.MStartValue + (this.YAxis.MInterval * j)) + ((this.YAxis.MInterval / (this.YAxis.MinorTicksCount + 1)) * (a + 1))); minorline.X1 = 0; minorline.X2 = this.ActualWidth; this.Children.Add(minorline); _yMinorLines.Add(minorline); } this.Children.Add(line); this._yLines.Add(line); } } else { int offset = _yLines.Count - (this.YAxis.MLabels.Count); for (int j = 0; j < offset; j++) { for (int a = 0; a < this.YAxis.MinorTicksCount; a++) { this.Children.Remove(_yMinorLines[_yMinorLines.Count - 1]); _yMinorLines.RemoveAt(_yMinorLines.Count - 1); } this.Children.Remove(_yLines[_yLines.Count - 1]); _yLines.RemoveAt(_yLines.Count - 1); } } for (int i = 0; i < YAxis.MLabels.Count - 1; i++) { Line line = _yLines[i]; line.X2 = this.ActualWidth; line.Y1 = yAxisHeightPosition; line.Y2 = yAxisHeightPosition; if (i != (this.YAxis.MLabels.Count - 1)) { for (int a = 0; a < this.YAxis.MinorTicksCount; a++) { Line minorline = _yMinorLines[yminorCount]; minorline.Y1 = this.YAxis.DataToPoint((this.YAxis.MStartValue + (this.YAxis.MInterval * i)) + ((this.YAxis.MInterval / (this.YAxis.MinorTicksCount + 1)) * (a + 1))); minorline.Y2 = this.YAxis.DataToPoint((this.YAxis.MStartValue + (this.YAxis.MInterval * i)) + ((this.YAxis.MInterval / (this.YAxis.MinorTicksCount + 1)) * (a + 1))); minorline.X1 = 0; minorline.X2 = this.ActualWidth; yminorCount++; } } yAxisHeightPosition += yAxisHeightStep; } } }
private void Initialize() { this.Children.Clear(); if (this.ActualHeight > 0 && this.ActualWidth > 0) { double xAxisWidthStep = this.ActualWidth / this.XAxis.MIntervalCount; double xAxisWidthPosition = 0; _xLines = new List <Line>(); _yLines = new List <Line>(); _xMinorLines = new List <Line>(); _yMinorLines = new List <Line>(); int k = 0; for (int i = 0; i < this.XAxis.MLabels.Count; i++) { Line line = new Line(); line.X1 = this.XAxis.DataToPoint(this.XAxis.MStartValue + (this.XAxis.MInterval * k)); line.X2 = this.XAxis.DataToPoint(this.XAxis.MStartValue + (this.XAxis.MInterval * k)); line.Y1 = 0; line.Y2 = this.ActualHeight; Binding styleBinding = new Binding { Path = new PropertyPath("CrossLineStyle"), Source = this.XAxis }; line.SetBinding(Line.StyleProperty, styleBinding); Binding showCrossLines = new Binding { Path = new PropertyPath("ShowCrossLines"), Source = this.XAxis }; showCrossLines.Converter = new BooleanToVisibilityConverter(); line.SetBinding(Line.VisibilityProperty, showCrossLines); if (i != (this.XAxis.MLabels.Count - 1)) { for (int a = 0; a < this.XAxis.MinorTicksCount; a++) { Line minorline = new Line(); Binding minorstyleBinding = new Binding { Path = new PropertyPath("MinorCrossLineStyle"), Source = this.XAxis }; minorline.SetBinding(Line.StyleProperty, minorstyleBinding); Binding minorshowCrossLines = new Binding { Path = new PropertyPath("ShowMinorCrossLines"), Source = this.XAxis }; minorshowCrossLines.Converter = new BooleanToVisibilityConverter(); minorline.SetBinding(Line.VisibilityProperty, minorshowCrossLines); minorline.X1 = this.XAxis.DataToPoint((this.XAxis.MStartValue + (this.XAxis.MInterval * k)) + ((this.XAxis.MInterval / (this.XAxis.MinorTicksCount + 1)) * (a + 1))); minorline.X2 = this.XAxis.DataToPoint((this.XAxis.MStartValue + (this.XAxis.MInterval * k)) + ((this.XAxis.MInterval / (this.XAxis.MinorTicksCount + 1)) * (a + 1))); minorline.Y1 = 0; minorline.Y2 = this.ActualHeight; this.Children.Add(minorline); _xMinorLines.Add(minorline); } } _xLines.Add(line); this.Children.Add(line); xAxisWidthPosition += xAxisWidthStep; k++; } double yAxisHeightStep = this.ActualHeight / this.YAxis.MIntervalCount; double yAxisHeightPosition = 0; int j = 0; for (int i = 0; i < YAxis.MLabels.Count; i++) { Line line = new Line(); line.X1 = 0; line.X2 = this.ActualWidth; line.Y1 = this.YAxis.DataToPoint(this.YAxis.MStartValue + (this.YAxis.MInterval * j)); line.Y2 = this.YAxis.DataToPoint(this.YAxis.MStartValue + (this.YAxis.MInterval * j)); Binding showCrossLines = new Binding { Path = new PropertyPath("ShowCrossLines"), Source = this.YAxis }; showCrossLines.Converter = new BooleanToVisibilityConverter(); line.SetBinding(Line.VisibilityProperty, showCrossLines); Binding styleBinding = new Binding { Path = new PropertyPath("CrossLineStyle"), Source = this.YAxis }; line.SetBinding(Line.StyleProperty, styleBinding); if (i != (this.YAxis.MLabels.Count - 1)) { for (int a = 0; a < this.YAxis.MinorTicksCount; a++) { Line minorline = new Line(); Binding minorstyleBinding = new Binding { Path = new PropertyPath("MinorCrossLineStyle"), Source = this.YAxis }; minorline.SetBinding(Line.StyleProperty, minorstyleBinding); Binding minorshowCrossLines = new Binding { Path = new PropertyPath("ShowMinorCrossLines"), Source = this.YAxis }; minorshowCrossLines.Converter = new BooleanToVisibilityConverter(); minorline.SetBinding(Line.VisibilityProperty, minorshowCrossLines); minorline.Y1 = this.YAxis.DataToPoint((this.YAxis.MStartValue + (this.YAxis.MInterval * j)) + ((this.YAxis.MInterval / (this.YAxis.MinorTicksCount + 1)) * (a + 1))); minorline.Y2 = this.YAxis.DataToPoint((this.YAxis.MStartValue + (this.YAxis.MInterval * j)) + ((this.YAxis.MInterval / (this.YAxis.MinorTicksCount + 1)) * (a + 1))); minorline.X1 = 0; minorline.X2 = this.ActualWidth; this.Children.Add(minorline); _yMinorLines.Add(minorline); } } this.Children.Add(line); this._yLines.Add(line); yAxisHeightPosition += yAxisHeightStep; j++; } _isInitialized = true; } }
/// <summary> /// Updates this instance. /// </summary> private void Update() { double xAxisWidthStep = (int)this.ActualWidth / this.XAxis.MIntervalCount; double xAxisWidthPosition = xAxisWidthStep; int xminorCount = 0; int yminorCount = 0; if ((this.XAxis.MLabels.Count) == _xLines.Count) { for (int i = 0; i < this.XAxis.MLabels.Count; i++) { Line line = _xLines[i]; line.X1 = xAxisWidthPosition; line.X2 = xAxisWidthPosition; line.Y2 = (int)this.ActualHeight; if (i != (this.XAxis.MLabels.Count - 1)) { for (int a = 0; a < this.XAxis.MinorTicksCount; a++) { Line minorline = _xMinorLines[xminorCount]; minorline.X1 = this.XAxis.DataToPoint((this.XAxis.MStartValue + (this.XAxis.MInterval * i)) + ((this.XAxis.MInterval / (this.XAxis.MinorTicksCount + 1)) * (a + 1))); minorline.X2 = this.XAxis.DataToPoint((this.XAxis.MStartValue + (this.XAxis.MInterval * i)) + ((this.XAxis.MInterval / (this.XAxis.MinorTicksCount + 1)) * (a + 1))); minorline.Y1 = 0; minorline.Y2 = this.ActualHeight; xminorCount++; } } xAxisWidthPosition += xAxisWidthStep; } } else { if ((this.XAxis.MLabels.Count) > _xLines.Count) { int offset = (this.XAxis.MLabels.Count) - _xLines.Count; for (int j = 0; j < offset; j++) { Line line = new Line {X1 = 0, X2 = 0, Y2 = this.ActualHeight}; Binding styleBinding = new Binding { Path = new PropertyPath("CrossLineStyle"), Source = this.XAxis }; Binding showCrossLines = new Binding { Path = new PropertyPath("ShowCrossLines"), Source = this.XAxis, Converter = new BooleanToVisibilityConverter() }; line.SetBinding(Line.VisibilityProperty, showCrossLines); line.SetBinding(Line.StyleProperty, styleBinding); for (int a = 0; a < this.XAxis.MinorTicksCount; a++) { Line minorline = new Line(); Binding minorstyleBinding = new Binding { Path = new PropertyPath("MinorCrossLineStyle"), Source = this.XAxis }; minorline.SetBinding(Line.StyleProperty, minorstyleBinding); Binding minorshowCrossLines = new Binding { Path = new PropertyPath("ShowMinorCrossLines"), Source = this.XAxis }; minorshowCrossLines.Converter = new BooleanToVisibilityConverter(); minorline.SetBinding(Line.VisibilityProperty, minorshowCrossLines); minorline.X1 = this.XAxis.DataToPoint((this.XAxis.MStartValue + (this.XAxis.MInterval * j)) + ((this.XAxis.MInterval / (this.XAxis.MinorTicksCount + 1)) * (a + 1))); minorline.X2 = this.XAxis.DataToPoint((this.XAxis.MStartValue + (this.XAxis.MInterval * j)) + ((this.XAxis.MInterval / (this.XAxis.MinorTicksCount + 1)) * (a + 1))); minorline.Y1 = 0; minorline.Y2 = this.ActualHeight; this.Children.Add(minorline); _xMinorLines.Add(minorline); } _xLines.Add(line); this.Children.Add(line); } } else { int offset = _xLines.Count - (this.XAxis.MLabels.Count); for (int j = 0; j < offset; j++) { for (int a = 0; a < this.XAxis.MinorTicksCount; a++) { this.Children.Remove(_xMinorLines[_xMinorLines.Count - 1]); _xMinorLines.RemoveAt(_xMinorLines.Count - 1); } this.Children.Remove(_xLines[_xLines.Count - 1]); _xLines.RemoveAt(_xLines.Count - 1); } } for (int i = 0; i < this.XAxis.MLabels.Count; i++) { Line line = _xLines[i]; line.X1 = xAxisWidthPosition; line.X2 = xAxisWidthPosition; line.Y2 = this.ActualHeight; if (i != (this.XAxis.MLabels.Count - 1)) { for (int a = 0; a < this.XAxis.MinorTicksCount; a++) { Line minorline = _xMinorLines[xminorCount]; minorline.X1 = this.XAxis.DataToPoint((this.XAxis.MStartValue + (this.XAxis.MInterval * i)) + ((this.XAxis.MInterval / (this.XAxis.MinorTicksCount + 1)) * (a + 1))); minorline.X2 = this.XAxis.DataToPoint((this.XAxis.MStartValue + (this.XAxis.MInterval * i)) + ((this.XAxis.MInterval / (this.XAxis.MinorTicksCount + 1)) * (a + 1))); minorline.Y1 = 0; minorline.Y2 = this.ActualHeight; xminorCount++; } } xAxisWidthPosition += xAxisWidthStep; } } double yAxisHeightStep = (int)this.ActualHeight / this.YAxis.MIntervalCount; double yAxisHeightPosition = yAxisHeightStep; if (YAxis.MLabels.Count == _yLines.Count) { for (int i = 0; i < YAxis.MLabels.Count ; i++) { Line line = _yLines[i]; line.X2 = this.ActualWidth; line.Y1 = yAxisHeightPosition; line.Y2 = yAxisHeightPosition; if (i != (this.YAxis.MLabels.Count - 1)) { for (int a = 0; a < this.YAxis.MinorTicksCount; a++) { Line minorline = _yMinorLines[yminorCount]; minorline.Y1 = this.YAxis.DataToPoint((this.YAxis.MStartValue + (this.YAxis.MInterval * i)) + ((this.YAxis.MInterval / (this.YAxis.MinorTicksCount + 1)) * (a + 1))); minorline.Y2 = this.YAxis.DataToPoint((this.YAxis.MStartValue + (this.YAxis.MInterval * i)) + ((this.YAxis.MInterval / (this.YAxis.MinorTicksCount + 1)) * (a + 1))); minorline.X1 = 0; minorline.X2 = this.ActualWidth; yminorCount++; } } yAxisHeightPosition += yAxisHeightStep; } } else { if ((this.YAxis.MLabels.Count) > _yLines.Count) { int offset = (this.YAxis.MLabels.Count) - _yLines.Count; for (int j = 0; j < offset; j++) { Line line = new Line(); line.X1 = 0; line.X2 = this.ActualWidth; line.Y1 = yAxisHeightPosition; line.Y2 = yAxisHeightPosition; Binding showCrossLines = new Binding { Path = new PropertyPath("ShowCrossLines"), Source = this.YAxis, Converter = new BooleanToVisibilityConverter() }; line.SetBinding(Line.VisibilityProperty, showCrossLines); Binding styleBinding = new Binding { Path = new PropertyPath("CrossLineStyle"), Source = this.YAxis }; line.SetBinding(Line.StyleProperty, styleBinding); for (int a = 0; a < this.YAxis.MinorTicksCount; a++) { Line minorline = new Line(); Binding minorstyleBinding = new Binding { Path = new PropertyPath("MinorCrossLineStyle"), Source = this.YAxis }; minorline.SetBinding(Line.StyleProperty, minorstyleBinding); Binding minorshowCrossLines = new Binding { Path = new PropertyPath("ShowMinorCrossLines"), Source = this.YAxis }; minorshowCrossLines.Converter = new BooleanToVisibilityConverter(); minorline.SetBinding(Line.VisibilityProperty, minorshowCrossLines); minorline.Y1 = this.YAxis.DataToPoint((this.YAxis.MStartValue + (this.YAxis.MInterval * j)) + ((this.YAxis.MInterval / (this.YAxis.MinorTicksCount + 1)) * (a + 1))); minorline.Y2 = this.YAxis.DataToPoint((this.YAxis.MStartValue + (this.YAxis.MInterval * j)) + ((this.YAxis.MInterval / (this.YAxis.MinorTicksCount + 1)) * (a + 1))); minorline.X1 = 0; minorline.X2 = this.ActualWidth; this.Children.Add(minorline); _yMinorLines.Add(minorline); } this.Children.Add(line); this._yLines.Add(line); } } else { int offset = _yLines.Count - (this.YAxis.MLabels.Count); for (int j = 0; j < offset; j++) { for (int a = 0; a < this.YAxis.MinorTicksCount; a++) { this.Children.Remove(_yMinorLines[_yMinorLines.Count - 1]); _yMinorLines.RemoveAt(_yMinorLines.Count - 1); } this.Children.Remove(_yLines[_yLines.Count - 1]); _yLines.RemoveAt(_yLines.Count - 1); } } for (int i = 0; i < YAxis.MLabels.Count-1; i++) { Line line = _yLines[i]; line.X2 = this.ActualWidth; line.Y1 = yAxisHeightPosition; line.Y2 = yAxisHeightPosition; if (i != (this.YAxis.MLabels.Count - 1)) { for (int a = 0; a < this.YAxis.MinorTicksCount; a++) { Line minorline = _yMinorLines[yminorCount]; minorline.Y1 = this.YAxis.DataToPoint((this.YAxis.MStartValue + (this.YAxis.MInterval * i)) + ((this.YAxis.MInterval / (this.YAxis.MinorTicksCount + 1)) * (a + 1))); minorline.Y2 = this.YAxis.DataToPoint((this.YAxis.MStartValue + (this.YAxis.MInterval * i)) + ((this.YAxis.MInterval / (this.YAxis.MinorTicksCount + 1)) * (a + 1))); minorline.X1 = 0; minorline.X2 = this.ActualWidth; yminorCount++; } } yAxisHeightPosition += yAxisHeightStep; } } }
private void Initialize() { this.Children.Clear(); if (this.ActualHeight > 0 && this.ActualWidth > 0) { double xAxisWidthStep = this.ActualWidth / this.XAxis.MIntervalCount; double xAxisWidthPosition = 0; _xLines = new List<Line>(); _yLines = new List<Line>(); _xMinorLines = new List<Line>(); _yMinorLines = new List<Line>(); int k = 0; for (int i = 0; i < this.XAxis.MLabels.Count; i++) { Line line = new Line(); line.X1 = this.XAxis.DataToPoint(this.XAxis.MStartValue + (this.XAxis.MInterval * k)); line.X2 = this.XAxis.DataToPoint(this.XAxis.MStartValue + (this.XAxis.MInterval * k)); line.Y1 = 0; line.Y2 = this.ActualHeight; Binding styleBinding = new Binding {Path = new PropertyPath("CrossLineStyle"), Source = this.XAxis}; line.SetBinding(Line.StyleProperty, styleBinding); Binding showCrossLines = new Binding { Path = new PropertyPath("ShowCrossLines"), Source = this.XAxis }; showCrossLines.Converter = new BooleanToVisibilityConverter(); line.SetBinding(Line.VisibilityProperty, showCrossLines); if (i != (this.XAxis.MLabels.Count - 1)) { for (int a = 0; a < this.XAxis.MinorTicksCount; a++) { Line minorline = new Line(); Binding minorstyleBinding = new Binding { Path = new PropertyPath("MinorCrossLineStyle"), Source = this.XAxis }; minorline.SetBinding(Line.StyleProperty, minorstyleBinding); Binding minorshowCrossLines = new Binding { Path = new PropertyPath("ShowMinorCrossLines"), Source = this.XAxis }; minorshowCrossLines.Converter = new BooleanToVisibilityConverter(); minorline.SetBinding(Line.VisibilityProperty, minorshowCrossLines); minorline.X1 = this.XAxis.DataToPoint((this.XAxis.MStartValue + (this.XAxis.MInterval * k)) + ((this.XAxis.MInterval / (this.XAxis.MinorTicksCount + 1)) * (a + 1))); minorline.X2 = this.XAxis.DataToPoint((this.XAxis.MStartValue + (this.XAxis.MInterval * k)) + ((this.XAxis.MInterval / (this.XAxis.MinorTicksCount + 1)) * (a + 1))); minorline.Y1 = 0; minorline.Y2 = this.ActualHeight; this.Children.Add(minorline); _xMinorLines.Add(minorline); } } _xLines.Add(line); this.Children.Add(line); xAxisWidthPosition += xAxisWidthStep; k++; } double yAxisHeightStep = this.ActualHeight / this.YAxis.MIntervalCount; double yAxisHeightPosition = 0; int j = 0; for (int i = 0; i < YAxis.MLabels.Count; i++) { Line line = new Line(); line.X1 = 0; line.X2 = this.ActualWidth; line.Y1 = this.YAxis.DataToPoint(this.YAxis.MStartValue + (this.YAxis.MInterval * j)); line.Y2 = this.YAxis.DataToPoint(this.YAxis.MStartValue + (this.YAxis.MInterval * j)); Binding showCrossLines = new Binding { Path = new PropertyPath("ShowCrossLines"), Source = this.YAxis }; showCrossLines.Converter = new BooleanToVisibilityConverter(); line.SetBinding(Line.VisibilityProperty, showCrossLines); Binding styleBinding = new Binding {Path = new PropertyPath("CrossLineStyle"), Source = this.YAxis}; line.SetBinding(Line.StyleProperty, styleBinding); if (i != (this.YAxis.MLabels.Count - 1)) { for (int a = 0; a < this.YAxis.MinorTicksCount; a++) { Line minorline = new Line(); Binding minorstyleBinding = new Binding { Path = new PropertyPath("MinorCrossLineStyle"), Source = this.YAxis }; minorline.SetBinding(Line.StyleProperty, minorstyleBinding); Binding minorshowCrossLines = new Binding { Path = new PropertyPath("ShowMinorCrossLines"), Source = this.YAxis }; minorshowCrossLines.Converter = new BooleanToVisibilityConverter(); minorline.SetBinding(Line.VisibilityProperty, minorshowCrossLines); minorline.Y1 = this.YAxis.DataToPoint((this.YAxis.MStartValue + (this.YAxis.MInterval * j)) + ((this.YAxis.MInterval / (this.YAxis.MinorTicksCount + 1)) * (a + 1))); minorline.Y2 = this.YAxis.DataToPoint((this.YAxis.MStartValue + (this.YAxis.MInterval * j)) + ((this.YAxis.MInterval / (this.YAxis.MinorTicksCount + 1)) * (a + 1))); minorline.X1 = 0; minorline.X2 = this.ActualWidth; this.Children.Add(minorline); _yMinorLines.Add(minorline); } } this.Children.Add(line); this._yLines.Add(line); yAxisHeightPosition += yAxisHeightStep; j++; } _isInitialized = true; } }