I have problem with rotate transform in my analog clock.

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;
}

I have this code for hour points, but this is moving only with one point. Is there any way how to change name of the ellipse in cycle for()?

有帮助吗?

解决方案

Apply the Transform to the individual hour markers and not the the entire Canvas:

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;     
}

And see Petzold for a really cool all XAML clock.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top