c# - 如何在xaml/c#中旋转图像

标签 c# windows-phone-7 xaml

我正在尝试旋转 <Image>箭头(放置在 40x40 图像的中间)。根据我在图形课上的内存,我需要先将图像平移回其中心,旋转然后再平移回来:

            TranslateTransform tTrans = new TranslateTransform();
            tTrans.X -= 20;
            tTrans.X -= 20;

            RotateTransform rTrans = new RotateTransform();
            rTrans.Angle = 60;

            TranslateTransform t2Trans = new TranslateTransform();
            tTrans.X += 20;
            tTrans.X += 20;

            imgWind.RenderTransform = ?;

有人知道我如何应用转换吗?

最佳答案

你可以简单地使用

imgWind.RenderTransform = new RotateTransform(){ CenterX = 0.5, CenterY = 0.5, Angle = 45 };

或者在 XAML 中:

<UIElement RenderTransformOrigin="0.5,0.5">
      <UIElement.RenderTransform>
      <RotateTransform CenterX="0.5" CenterY="0.5" Angle="45" />
      </UIElement.RenderTransform>
</UIElement>

通过设置 CenterX 和 CenterY,您不必转换之前和之后。在 WPF(或 silverlight)中,转换将自行处理。

关于c# - 如何在xaml/c#中旋转图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9444071/

相关文章:

.net - Horizo​​ntalAlignment 设置为 Stretch 和 Left 的 TextBox

c# - c#中的方法锁

c# - Windows Phone 7 从应用程序访问 Dropbox

c# - WP7 ListBox 选中的项目没有改变颜色

c# - 将整个文件夹复制到 IsoStorage

c# - 在 Visual Studio 设计器中为控件指定双击事件

c# - 使用登录控件显示自定义错误消息时出现问题。

c# - 如何在 Visual Studio 2012 中添加引用 `Microsoft.TeamFoundation.TestImpact.Client.dll`?

c# - 改文件名显示不改原名

wpf - WPF 如何处理对空对象属性的绑定(bind)?