Beispiel #1
0
        /// <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);
        }
Beispiel #2
0
        /// <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 dQuarter = DipHelper.InchToDip(dUnit + 0.25) * this.Zoom;
                            drawingContext.DrawLine(ThinPen, new Point(dQuarter, 0),
                                                    new Point(dQuarter, SegmentHeight / 3.0));
                            double dMiddle = DipHelper.InchToDip(dUnit + 0.5) * this.Zoom;
                            drawingContext.DrawLine(p, new Point(dMiddle, 0),
                                                    new Point(dMiddle, SegmentHeight * 2D / 3D));
                            double d3Quarter = DipHelper.InchToDip(dUnit + 0.75) * this.Zoom;
                            drawingContext.DrawLine(ThinPen, new Point(d3Quarter, 0),
                                                    new Point(d3Quarter, SegmentHeight / 3.0));
                        }
                        else
                        {
                            double dQuarter = DipHelper.InchToDip(dUnit + 0.25) * this.Zoom;
                            drawingContext.DrawLine(ThinPen, new Point(dQuarter, Height),
                                                    new Point(dQuarter, Height - SegmentHeight / 3.0));
                            double dMiddle = DipHelper.InchToDip(dUnit + 0.5) * this.Zoom;
                            drawingContext.DrawLine(p, new Point(dMiddle, Height),
                                                    new Point(dMiddle, Height - SegmentHeight * 2D / 3D));
                            double d3Quarter = DipHelper.InchToDip(dUnit + 0.75) * this.Zoom;
                            drawingContext.DrawLine(ThinPen, new Point(d3Quarter, Height),
                                                    new Point(d3Quarter, Height - 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));
                    }
                }
            }
        }