Click here to Skip to main content
15,914,488 members
Please Sign up or sign in to vote.
2.33/5 (2 votes)
See more:
I am having problem with displaying a text inside a canvas. I can add text, but it display as 180 flip into the page. I know it has something to do with the
C#
RenderTransform="1 0 0 -1 0 0"></Canvas>
that I used, but I wanted to keep the canvas RenderTransform this way because I have done many other stuff with this setup already.

I just now need to rotate the text 180-degree into the page ... so to flip it... if you know what I mean.


Here is a piece of code that I use for drawing text..

C#
TextBlock textBlock = new TextBlock();
textBlock.Text = text;
textBlock.Foreground = new SolidColorBrush(color);
//Canvas.SetLeft(textBlock, x);
//Canvas.SetTop(textBlock, y);
textBlock.RenderTransform = new RotateTransform(-90, 0, 0); // this line can rotate it but not in the axis i want
textBlock.Margin = new Thickness(100, 100, 0, 0);
canvas1.Children.Add(textBlock);
Posted
Updated 31-Jul-13 6:51am
v2

1 solution

Apparently, from simple 2D geometry you can easily see, that you cannot reduce flip operation to any combination rotations. "Flipping" means inverting one of the axes. To flip, you need to use System.Windows.Media.ScaleTransform with negative scale factor for one of the axes:
http://msdn.microsoft.com/en-us/library/system.windows.uielement.rendertransform.aspx[^] (look at the first example with the text "Flip me"),
http://msdn.microsoft.com/en-us/library/system.windows.media.scaletransform.aspx[^].

—SA
 
Share this answer
 
Comments
Jaxam 31-Jul-13 15:08pm    
Thanks. I looked up the XAML and thought this would works

textBlock.RenderTransform = new ScaleTransform(-1,0,0,0);

but apparently not. I am doing it incorrect? The text not even show up on the canvas after that scaltransform :(
Sergey Alexandrovich Kryukov 31-Jul-13 15:42pm    
It simply moved out of the view. Combine it with translate transform or simply modify center parameters (two last ones). Play a bit with transforms, and you will easily put it right...
—SA

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900