How do you rotate text in a text block in C # (Code-Behind) ~~

Basically, I am currently doing a project last year at my college in which I touch on the surface of WPF 2.0.

My project is a game in which if the user answers the question incorrectly, the next question will be rotated to make it more difficult. But I'm not sure how to do this. I saw an example in msdn microsoft, but it only shows XAML codes. I need C # codes.

Here is an example of XAML.

http://msdn.microsoft.com/en-us/library/ms754028.aspx

Last example

Here is part of my verification codes. I need to activate the animation if the user responds incorrectly.

if (surfaceRadioButton1.IsChecked == true) { user_answer = (string)surfaceRadioButton1.Content; textBlock2.Text = validateAnswer(user_answer, answer); retreiveYellowQns(); if (textBlock2.Text.Equals("Correct")) { yellow_coord = yellow_coord + 50; Canvas.SetLeft(car, yellow_coord); Canvas.SetTop(car, 289); } else { if (yellow_coord <= 330) { yellow_coord = 330; Canvas.SetLeft(car, yellow_coord); Canvas.SetTop(car, 289); } else { yellow_coord = yellow_coord - 50; Canvas.SetLeft(car, yellow_coord); Canvas.SetTop(car, 289); } } } 

Any help would be appreciated, thanks in advance.

+8
animation wpf textblock pixelsense
source share
3 answers

Try it. You can use animation in RenderTransform:

 var rotateAnimation = new DoubleAnimation(0, 180, TimeSpan.FromSeconds(5)); var rt = (RotateTransform) textblock2.RenderTransform; rt.BeginAnimation(RotateTransform.AngleProperty, rotateAnimation); 

In your Xaml, you can add RotateTransform:

 <TextBlock> <TextBlock.RenderTransform> <RotateTransform Angle="0"/> </TextBlock.RenderTransform> </TextBlock> 
+10
source share

For this you will have to use Transformation. Try this answer https://stackoverflow.com>

Or you can also try (I have not tried this). See this article for more details.

 textBlock2.RenderTransform = new RotateTransform(IntegerAngleValue); 
+6
source share
  var rotateAnimation = new DoubleAnimation(180, 0, TimeSpan.FromMilliseconds(200)); UiImage.RenderTransformOrigin = new Point(0.5,0.5); UiImage.RenderTransform = new RotateTransform(); var rt = (RotateTransform)UiImage.RenderTransform; rt.BeginAnimation(RotateTransform.AngleProperty, rotateAnimation); 
+1
source share

All Articles