tags:

views:

205

answers:

3

I've figured out how to assign a rotation value (element.RenderTransform = new RotateTransform(x)), but how do I get the rotation value of the element?

For example, if I wanted to make one ui element have the same rotation angle as another ui element, how would I do that?

+3  A: 

You can get the rotation value by doing:

RotateTransform rotation = element.RenderTransform as RotateTransform;
if (rotation != null) // Make sure the transform is actually a RotateTransform
{
    double rotationInDegrees = rotation.Angle;
    // Do something with the rotationInDegrees here, if needed...
}

If you want to just make another UIelement rotate in the same way, you can just assign the same transform:

element2.RenderTransform = element.RenderTransform;
Reed Copsey
+2  A: 

You can name the RotateTransform and then bind to its properties. For example, in your 'main' ui element, you define the transform as so:

<TextBlock Text="MainBox">
  <TextBlock.RenderTransform>
    <RotateTransform Angle="20" 
                     CenterX="50" 
                     CenterY="50" 
                     x:Name="m"/>
  </TextBlock.RenderTransform>
</TextBlock>

Then you can bind to that transform from another element:

<TextBlock Text="SecondBox">
  <TextBlock.RenderTransform>
    <RotateTransform Angle="{Binding Angle, ElementName=m}"
                     CenterX="{Binding CenterX, ElementName=m}" 
                     CenterY="{Binding CenterY, ElementName=m}"/>
  </TextBlock.RenderTransform>
</TextBlock>
Ben Collier
A: 

i got this kind of problem also.

<Image x:Name="myphoto" RenderTransformOrigin="0.5,0.5" Width="263" Height="258" Source="Images/photo.png" Stretch="Fill">
            <Image.RenderTransform>
                <TransformGroup x:Name="tg">
                    <ScaleTransform ScaleX="0.6" ScaleY="0.6"/>
                    <SkewTransform/>
                    <RotateTransform Angle="0" x:Name="rt"/>
                    <TranslateTransform/>
                </TransformGroup>
            </Image.RenderTransform>
        </Image>

<TextBlock x:Name="txt" Text="{Binding Angle, ElementName=rt}">

when the image rotates, the text value does not showing anything. completely blank.

any solution on this?

Murad Mohd Zain