Exemplo n.º 1
0
        private void DrawTicks(Canvas canvas, double yPos)
        {
            var canvasWidth = canvas.ActualWidth;

            var timeLineLength = canvasWidth - FingerWidthInUnits;

            var timeLineStart = HalfFingerWidthInUnits;

            var minimumDuration = (_timeRange.Duration / timeLineLength) * FingerWidthInUnits;

            var tickInterval = TickIntervals.GetFirstTickIntervalWithGreaterDuration(minimumDuration);

            var ticks = tickInterval.GetTicksBetween(_timeRange.Start, _timeRange.End);

            foreach (var tick in ticks)
            {
                var tickXPos = timeLineStart + ((tick.Date - _timeRange.Start) / _timeRange.Duration) * timeLineLength;

                var tickLine = new Line();

                tickLine.X1 = tickXPos;
                tickLine.Y1 = yPos;
                tickLine.X2 = tickXPos;
                tickLine.Y2 = yPos + 4;

                tickLine.Fill            = Brushes.Black;
                tickLine.Stroke          = Brushes.Black;
                tickLine.StrokeThickness = 2;

                canvas.Children.Add(tickLine);

                var tickLabel = new TextBlock();
                tickLabel.TextAlignment = TextAlignment.Center;

                var labelText = tick.ToString();

                var pixelsPerDip = VisualTreeHelper.GetDpi(this).PixelsPerDip;

                var formattedText = new FormattedText(
                    labelText,
                    CultureInfo.CurrentUICulture,
                    FlowDirection.LeftToRight,
                    tickLabel.FontFamily.GetTypefaces().First(),
                    tickLabel.FontSize,
                    Brushes.Black,
                    pixelsPerDip
                    );

                tickLabel.Text = labelText;
                tickLabel.SetValue(Canvas.LeftProperty, tickXPos - (formattedText.Width / 2));
                tickLabel.SetValue(Canvas.TopProperty, yPos + 4);

                canvas.Children.Add(tickLabel);
            }
        }
Exemplo n.º 2
0
 private TickInterval GetFirstTickIntervalWithGreaterDuration(Duration duration)
 {
     return(TickIntervals.GetFirstTickIntervalWithGreaterDuration(duration));
 }