locked
Why Rotate image only fire once

    Question

  • I would like to let user keep rotating image or canvas left and right as many times as they like.

    I have a Canvas contain image

     <Canvas  x:Name="canvas" Margin="231,28,321,111" Width="700" Height="525" Grid.Row="0" Grid.RowSpan="3" Grid.Column="0">
        <Image Canvas.Top="0" Canvas.Left="0" Margin="0" x:Name="preview" Width="700" Height="525"  Stretch="UniformToFill" >
        </Image>
     </Canvas>

    This code only fire one. What I need to change to make it such that user can keep rotating left or right as many times as they like?

    private void CamRotate90_Click(object sender, RoutedEventArgs e)
            {           
                CompositeTransform ct = new CompositeTransform();
                ct.CenterX = canvas.ActualWidth / 2;
                ct.CenterY = canvas.ActualHeight/2;
                ct.Rotation = 90;       

                canvas.RenderTransform = ct;
              
              }

    1) I can't tell this is rotate right or left

    2) How to rotate left right after rotate right or vis a vis.

    Thanks

    Tuesday, November 4, 2014 7:15 AM

Answers

  • try

    int basevalue = -30; private void Button_Click(object sender, RoutedEventArgs e) { CompositeTransform ct = new CompositeTransform(); ct.CenterX = canvas.ActualWidth / 2; ct.CenterY = canvas.ActualHeight / 2; ct.Rotation = basevalue;

    basevalue += basevalue; canvas.RenderTransform = ct; }


    rotate left, use negative number


    在現實生活中,你和誰在一起的確很重要,甚至能改變你的成長軌跡,決定你的人生成敗。 和什麼樣的人在一起,就會有什麼樣的人生。 和勤奮的人在一起,你不會懶惰; 和積極的人在一起,你不會消沈; 與智者同行,你會不同凡響; 與高人為伍,你能登上巔峰。

    • Marked as answer by FireDance Wednesday, November 5, 2014 3:04 AM
    Tuesday, November 4, 2014 10:11 AM

All replies

  • try

    int basevalue = -30; private void Button_Click(object sender, RoutedEventArgs e) { CompositeTransform ct = new CompositeTransform(); ct.CenterX = canvas.ActualWidth / 2; ct.CenterY = canvas.ActualHeight / 2; ct.Rotation = basevalue;

    basevalue += basevalue; canvas.RenderTransform = ct; }


    rotate left, use negative number


    在現實生活中,你和誰在一起的確很重要,甚至能改變你的成長軌跡,決定你的人生成敗。 和什麼樣的人在一起,就會有什麼樣的人生。 和勤奮的人在一起,你不會懶惰; 和積極的人在一起,你不會消沈; 與智者同行,你會不同凡響; 與高人為伍,你能登上巔峰。

    • Marked as answer by FireDance Wednesday, November 5, 2014 3:04 AM
    Tuesday, November 4, 2014 10:11 AM
  • Hi Bill,

    Thank for your quick reply.

    I tried your code and I have these questions.

    1) If I use -30, I can rotate many times or even infinitely. in this case, it works.

    2) I need to rotate at 90 degree for my photo.

    when I rotate at 90 degree( basevalue =-90 or 90), I can ONLY rotate 3 times.

    I want to rotate as many times as possible just like case (1) above and rotate at 90 degree, can you show what I need to do.

    thanks

    Tuesday, November 4, 2014 11:04 AM
  • Thanks Bill. The problem is solved. when basevalue reach 360, I just make back to 90.

    Thanks.

    Wednesday, November 5, 2014 3:05 AM