简体   繁体   English

旋转的文本块长度不正确

[英]Rotated textblock doesn't have the correct length

I am trying to fill a Grid in a WPF application dynamically. 我正在尝试动态填充WPF应用程序中的网格。

I'm creating a row and then some columns. 我先创建一行,然后创建一些列。 in each column I am adding a textblock, like this: 在每一列中,我都添加一个文本块,如下所示:

GrdMainGrid.RowDefinitions.Add(new RowDefinition(Height = new GridLength(150, GridUnitType.Pixel);
GrdMainGrid.RowDefinitions.Add(new RowDefinition(Height = new GridLength(1, GridUnitType.Star);

for(var i=0; i<4; i++)
{
  GrdMainGrid.ColumnDefinitions.Add(new ColumnDefinition {With = new GridLength(25, GridUnitType.Pixel)});
}
var header = new TextBlock {Text = "Header1", RenderTransform = new RotateTransform(-90), Width = 150, Margin = new Thickness(0), VerticalAlignment = VerticalAlignment.Bottom, HorizontalAlignment = HorizontalAlignment.Left};
.
.
.
Grid.SetColumn(header, 0);
Grid.SetRow(header, 0);
.
.
.
GrdMainGrid.Children.Add(header);

The textblock is rotated -90 degree. 文本块旋转-90度。 While the size of the column is set to 25 pixel i doesn't show all text, when I increase the size of the column the text in textblock is also increased. 当列的大小设置为25像素时,我不会显示所有文本,但是当我增加列的大小时,textblock中的文本也会增加。 see pic 看图片 在此处输入图片说明

在此处输入图片说明

I could understand this if the textblock wasn't rotated and it didn't fit in the column. 如果文本块没有旋转并且它不适合列,我可以理解这一点。 But what has it to do with the size of the column when it's rotated. 但是,它与旋转列时的大小有关。 And is it possible somehow to decrease the width of the column without decreasing size of text ? 并且有可能以某种方式减小列的宽度而不减小文本的大小吗? Tnx in advance. 提前Tnx。

使用LayoutTransform而不是RenderTransform。

    var header = new TextBlock { Text = "Header1", LayoutTransform = new RotateTransform(-90), Width = 150, Margin = new Thickness(0), VerticalAlignment = VerticalAlignment.Bottom, HorizontalAlignment = HorizontalAlignment.Left };

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM