/// <summary> /// Measures an instance during the first layout pass prior to arranging it. /// </summary> /// <param name="availableSize">A maximum Size to not exceed.</param> /// <returns>The maximum Size for the instance.</returns> protected override Size MeasureOverride(Size availableSize) { Size desiredSize; if (Unit == Unit.Cm) { desiredSize = new Size(DipHelper.CmToDip(Length), Height); } else { desiredSize = new Size(DipHelper.InchToDip(Length), Height); } return(desiredSize); }
/// <summary> /// Participates in rendering operations. /// </summary> /// <param name="drawingContext">The drawing instructions for a specific element. This context is provided to the layout system.</param> protected override void OnRender(DrawingContext drawingContext) { base.OnRender(drawingContext); double xDest = (Unit == Unit.Cm ? DipHelper.CmToDip(Length) : DipHelper.InchToDip(Length)) * this.Zoom; drawingContext.DrawRectangle(null, BorderPen, new Rect(new Point(0.0, 0.0), new Point(xDest, Height))); double chip = Unit == Unit.Cm ? DipHelper.CmToDip(Chip) : DipHelper.InchToDip(Chip); drawingContext.DrawLine(RedPen, new Point(chip, 0), new Point(chip, Height)); for (double dUnit = 0; dUnit <= Length; dUnit++) { double d; if (Unit == Unit.Cm) { d = DipHelper.CmToDip(dUnit) * this.Zoom; if (dUnit < Length) { for (int i = 1; i <= 9; i++) { if (i != 5) { double dMm = DipHelper.CmToDip(dUnit + 0.1 * i) * this.Zoom; if (Marks == MarksLocation.Up) { drawingContext.DrawLine(ThinPen, new Point(dMm, 0), new Point(dMm, SegmentHeight / 3.0)); } else { drawingContext.DrawLine(ThinPen, new Point(dMm, Height), new Point(dMm, Height - SegmentHeight / 3.0)); } } } double dMiddle = DipHelper.CmToDip(dUnit + 0.5) * this.Zoom; if (Marks == MarksLocation.Up) { drawingContext.DrawLine(p, new Point(dMiddle, 0), new Point(dMiddle, SegmentHeight * 2.0 / 3.0)); } else { drawingContext.DrawLine(p, new Point(dMiddle, Height), new Point(dMiddle, Height - SegmentHeight * 2.0 / 3.0)); } } } else { d = DipHelper.InchToDip(dUnit) * this.Zoom; if (dUnit < Length) { if (Marks == MarksLocation.Up) { double unit = 0.125d; for (int i = 0; i < 8; i++) { double length = DipHelper.InchToDip(dUnit + ((i + 1) * unit)) * this.Zoom; if ((i + 1) % 4 == 0) { drawingContext.DrawLine(ThinPen, new Point(length, 0), new Point(length, SegmentHeight * 2D / 3D)); } else { drawingContext.DrawLine(ThinPen, new Point(length, 0), new Point(length, SegmentHeight / 3.0)); } } } else { double unit = 0.125d; for (int i = 0; i < 8; i++) { double length = DipHelper.InchToDip(dUnit + ((i + 1) * unit)) * this.Zoom; if ((i + 1) % 4 == 0) { drawingContext.DrawLine(ThinPen, new Point(length, Height), new Point(length, SegmentHeight * 2D / 3D)); } else { drawingContext.DrawLine(ThinPen, new Point(length, Height), new Point(length, SegmentHeight / 3.0)); } } } } } if (Marks == MarksLocation.Up) { drawingContext.DrawLine(p, new Point(d, 0), new Point(d, SegmentHeight)); } else { drawingContext.DrawLine(p, new Point(d, Height), new Point(d, Height - SegmentHeight)); } if ((dUnit != 0.0) && (dUnit < Length)) { FormattedText ft = new FormattedText( (dUnit + CountShift).ToString(CultureInfo.CurrentCulture), CultureInfo.CurrentCulture, FlowDirection.LeftToRight, new Typeface("Arial"), DipHelper.PtToDip(6), Brushes.DimGray); ft.SetFontWeight(FontWeights.Regular); ft.TextAlignment = TextAlignment.Center; if (Marks == MarksLocation.Up) { drawingContext.DrawText(ft, new Point(d, Height - ft.Height)); } else { drawingContext.DrawText(ft, new Point(d, Height - SegmentHeight - ft.Height)); } } } }