Pregunta

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()?

¿Fue útil?

Solución

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.

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top