如何在C#(Code-Behind)中旋转文本块中的文本~~

Joo*_*iat 9 wpf animation textblock pixelsense

基本上我目前在我的大学做最后一年的项目,我接触表面2.0 WPF.

我的项目是一个游戏,如果用户错误地回答问题,下一个问题将被轮换以使其更加困难.但我不确定该怎么做.我在msdn microsoft中看到了一个例子,但它只显示了XAML代码.我需要C#代码.

这是XAML示例.

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

最后一个例子

这是我的验证码的一部分.如果用户回答错误,我需要激活动画.

 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);
                }
            }
        }
Run Code Online (Sandbox Code Playgroud)

任何帮助都会很高兴,提前谢谢.

ElG*_*cho 11

试试这个吧.您可以在RenderTransform上使用动画:

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

在您的Xaml中,您可以添加RotateTransform:

<TextBlock>
  <TextBlock.RenderTransform>
    <RotateTransform Angle="0"/>
  </TextBlock.RenderTransform>
</TextBlock>
Run Code Online (Sandbox Code Playgroud)


Mah*_*eep 7

你必须为此使用Transformation.试试这个答案/sf/answers/617076211/

或者你也可以尝试,(我还没试过)看看这篇文章了解更多细节

textBlock2.RenderTransform = new RotateTransform(IntegerAngleValue); 
Run Code Online (Sandbox Code Playgroud)