tags:

views:

413

answers:

1

Hi,

I'm writing an application that creates a graphical 'dial', like a clock. Each element in the dial is created and then added to the dial in a clockwise fashion - imagine creating a single element with the hour 1 that includes the minute strokes, the number '1' and other embelishments, drawing it, then repeting for the hour 2, etc.

Rather than recalculating the plotting angles and positions for each element in the dial, depending on where the dial element is to be positioned/rotated, can I create all the lines, ticks and text etc for each element as a graphical 'group' and then perform a rotate transform on this entire group?

Thanks for any help.

A: 

Yes. Use a grid, place all the other objects and or controls on that grid and then specify a view transformation for the grid to rotate it a number of degree's.

i.e. To transform everything on the grid by 45 degrees it would look like this in XAML;

    <Grid x:Name="LayoutRoot" RenderTransformOrigin="0.5,0.5">
     <Grid.RenderTransform>
      <TransformGroup>
       <ScaleTransform/>
       <SkewTransform/>
       <RotateTransform Angle="45"/>
       <TranslateTransform/>
      </TransformGroup>
     </Grid.RenderTransform>
     <Rectangle Fill="White" Stroke="Black" Margin="198,161,265,196"/>
    </Grid>

This example only has a single rectangle on the gird but the concept is exactly the same regardless how many objects are included.

To adjust the rotation latter through C# you can then use following, which will rotate the Grid by 90 degrees:

RotateTransform aRT = new RotateTransform(90);
this.LayoutRoot.RenderTransform = aRT;
Sebastian Gray
Hi, thanks for the reply, can you help further?I'd like to know how to do this all in c#, since the number of elements in my dial is variable. should I just create a new grid for each new element and then transform each one as I create it?Also, the dial is editable by the user, who can add new elements, delete them etc, and each time the dial is modified, it would have to be redrawn - so I am assuming that for each element I would have to...
Will
- dynamically create a new grid - add graphics to it- draw it- be able to destroy it and redraw the whole dial since I don't know how many elements there will be in my dial, because they are created by the user at runtime, I can't create grids that have a named variable, but if the grid is not named, how do I delete it later?thanks,Will.
Will