private void OnCanvasLoaded(object sender, RoutedEventArgs e) { Canvas canvas = (Canvas)sender; RegisterNames(canvas); _pixelsPerDip = VisualTreeHelper.GetDpi(this).PixelsPerDip; _canvasWidth = canvas.ActualWidth; _canvasHeight = canvas.ActualHeight; _time.FontSize = 12; _time.FontWeight = FontWeights.Bold; double outerRadiusFactor = 0.24; double innerRadiusFactor = 0.15; _outerCircleRadius = (int)(_canvasHeight * outerRadiusFactor); _outerCircleDiameter = _outerCircleRadius * 2; _innerCircleRadius = (int)(_canvasHeight * innerRadiusFactor); var totalWidthNeeded = 3.25 * _outerCircleDiameter; _centrePoint = CalcCentrePoint(totalWidthNeeded); _donut.Data = PieSlice.Get(0.1, _centrePoint, _innerCircleRadius, _outerCircleRadius); _secondsBall.Width = (double)_innerCircleRadius / 6; _secondsBall.Height = (double)_innerCircleRadius / 6; _time.Text = GetTimeText(); Size sz = GetTextSize(useExtent: true); while (sz.Height < (3 * (double)_outerCircleDiameter) / 4) { _time.FontSize += 0.5; sz = GetTextSize(useExtent: true); } sz = GetTextSize(useExtent: true); Canvas.SetLeft(_time, _centrePoint.X - _outerCircleRadius + totalWidthNeeded - sz.Width); Canvas.SetTop(_time, _centrePoint.Y - sz.Height); RenderPieSliceAndBall(0.1, 0); Visibility = Visibility.Visible; Animations.FadeIn(this, new FrameworkElement[] { _donut, _secondsBall, _pie, _time }); }
private void RenderPieSliceAndBall(double angle, double secondsElapsed) { if (!Dispatcher.HasShutdownStarted) { _pie.Data = PieSlice.Get(angle, _centrePoint, _innerCircleRadius, _outerCircleRadius); Point ballPt = SecondsBall.GetPos( _centrePoint, (int)secondsElapsed % 60, _secondsBall.Width / 2, _innerCircleRadius); Canvas.SetLeft(_secondsBall, ballPt.X); Canvas.SetTop(_secondsBall, ballPt.Y); _time.Text = GetTimeText(); } }