1

I am wondering if someone might be able to help me solve a display issue. I want to simply allow for a clockwise rotation 90 degrees using the code below:

        RotateTransform rotateTransform = new RotateTransform();
        rotateTransform.CenterX = image1.Width / 2.0;
        rotateTransform.CenterY = image1.Height / 2.0;
         cW+= 90;

        rotateTransform.Angle = cW;

        TransformGroup transformGroup = new TransformGroup();
        transformGroup.Children.Add(rotateTransform);


        image1.RenderTransform = transformGroup;

In XAML, when I define the image height and width, the image WILL rotate. However, when set to auto the image disappears after this code is executed. Why is this happening and how can I solve this problem? Any help would be greatly appreciated.

4

1 に答える 1

5

おそらく、画像のActualHeightandを使用する必要がありますActualWidth:

RotateTransform rotateTransform = new RotateTransform();
rotateTransform.CenterX = image1.ActualWidth / 2.0;
rotateTransform.CenterY = image1.ActualHeight / 2.0;

高さと幅を明示的に設定すると、これらは同じになります。未設定の場合、高さと幅が設定されていないため、中心が間違っています。

于 2013-02-06T18:52:28.100 に答える