如何在 C# 中旋转文本块中的文本(代码隐藏)~~
基本上,我目前正在大学做最后一年的项目,其中涉及 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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
试试这个。您可以在 RenderTransform 上使用动画:
在 Xaml 中,您可以添加 RotateTransform:
Try this one. You can use an animation on the RenderTransform:
In your Xaml, you can add the RotateTransform:
为此,您必须使用转换。尝试这个答案 https://stackoverflow.com/a/8815374/293712
或者你也可以尝试,(我没有尝试过这个)看看 这篇文章了解更多详情
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