模拟时钟旋转变换

时间:2014-02-02 12:03:09

标签: c# wpf clock rotatetransform

我的模拟时钟旋转变换有问题。

for (int i = 0; i <= 12; i++)
{
    Ellipse teckaa = new Ellipse();
    teckaa.Height = 30;
    teckaa.Width = 30;
    teckaa.Stroke = Brushes.Black;
    teckaa.Fill = Brushes.Black;
    canvas.Children.Add(teckaa);
    Canvas.SetTop(teckaa, 25);
    Canvas.SetLeft(teckaa, 215);
    RotateTransform otoceni = new RotateTransform(i*30, 230, 230);
    canvas.RenderTransform = otoceni;
}

我有这个代码用于小时点,但这只是一点点。有没有办法如何在()?

的循环中更改椭圆的名称

1 个答案:

答案 0 :(得分:0)

将变换应用于各个小时标记,而不是整个画布:

for (int i = 0; i <= 12; i++)
{
    Ellipse teckaa = new Ellipse();
    teckaa.Height = 30;
    teckaa.Width = 30;
    teckaa.Stroke = Brushes.Black;
    teckaa.Fill = Brushes.Black;
    canvas.Children.Add(teckaa);
    Canvas.SetTop(teckaa, 25);
    Canvas.SetLeft(teckaa, 215);
    RotateTransform otoceni = new RotateTransform(i*30, 230, 230);

    //canvas.RenderTransform = otoceni;
    teckaa.RenderTransform = otoceni;     
}

看到Petzold真的很酷all XAML clock