如何在 C# 中旋转文本块中的文本(代码隐藏)~~

发布于 2024-12-29 11:14:15 字数 1371 浏览 5 评论 0原文

基本上,我目前正在大学做最后一年的项目,其中涉及 Surface 2.0 WPF。

我的项目是一个游戏,如果用户回答错误,下一个问题将被轮换以使其变得更加困难。但我不确定该怎么做。我在 microsoft msdn 中看到了一个示例,但它只显示 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);
                }
            }
        }

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

Basically I am currently doing final year project in my college whereby i am touching on surface 2.0 WPF.

My project is a game whereby if a user answer a question wrongly,the next question will be rotated to make it more difficult. But I am unsure how to do it. I saw an example in msdn microsoft but it only shows XAML codes. I need the C# codes.

Here's the XAML example.

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

The last example

Here's part of my validation codes. I need to activate the animation if user answer wrongly.

 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 will be glad,thanks in advance.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

过期以后 2025-01-05 11:14:15

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

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

在 Xaml 中,您可以添加 RotateTransform:

<TextBlock>
  <TextBlock.RenderTransform>
    <RotateTransform Angle="0"/>
  </TextBlock.RenderTransform>
</TextBlock>

Try this one. You can use an animation on the 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 the RotateTransform:

<TextBlock>
  <TextBlock.RenderTransform>
    <RotateTransform Angle="0"/>
  </TextBlock.RenderTransform>
</TextBlock>
小傻瓜 2025-01-05 11:14:15

为此,您必须使用转换。尝试这个答案 https://stackoverflow.com/a/8815374/293712

或者你也可以尝试,(我没有尝试过这个)看看 这篇文章了解更多详情

textBlock2.RenderTransform = new RotateTransform(IntegerAngleValue); 

You will have to use Transformation for this. Try this answer https://stackoverflow.com/a/8815374/293712

Or You can also try, (I have not tried this) Look at this article for more details

textBlock2.RenderTransform = new RotateTransform(IntegerAngleValue); 
东北女汉子 2025-01-05 11:14:15
            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);
            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);
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文