【发布时间】:2017-10-23 18:54:12
【问题描述】:
我想在画布上添加一些文本并决定为此使用textBlock(设置字体等)
但我不知道如何旋转它。
我使用以下函数在myCanvas上添加myText:
void text(double x_pos, double y_pos, string myText, double angle, Point rot_cen, Color color1)
{
TextBlock textBlock = new TextBlock()
{
Text = myText,
FontFamily = new FontFamily("Verdana"),
FontSize = 16,
TextAlignment = TextAlignment.Center
};
textBlock.Foreground = new SolidColorBrush(color1);
Canvas.SetLeft(textBlock, x_pos);
Canvas.SetTop(textBlock, y_pos);
textBlock.RenderTransform = new RotateTransform(angle, rot_cen.X, rot_cen.Y);
myCanvas.Children.Add(textBlock);
}
从我读到的rot_cen 是从(0,0)(左上角)到(1,1)(右下角)的一个点。但是当我将它设置为(0.5,0.5)时,它仍然围绕左上角旋转。我需要以某种方式更新它吗?
【问题讨论】:
标签: wpf canvas rotatetransform