【发布时间】:2019-02-18 12:39:45
【问题描述】:
我在画布背景上有网格,可以在图片中看到。在第一行,我想标记列。为此,我使用了 TextBlock。但是当字符数增加时,我无法看到 TextBlock 的全部内容。例如,当内容为 9990 时,我可以看到它,但在下一个标签中,内容为 10020,其中包含更多字符。我只能看到 1002。矩形大小为 30,即绘制网格。 TextBlock Width 为 27,TextBlock 的 Margin 为 3。enter image description here我不想更改字体大小。
<Canvas x:Name="back_canvas" Height="12000" Width="{Binding CanvasWidth , UpdateSourceTrigger=PropertyChanged, Mode=TwoWay}" VerticalAlignment="Top" HorizontalAlignment="Left" Margin="0,0,10,0" >
<Canvas.Background>
<DrawingBrush TileMode="Tile" Viewport="0,0,30,30" ViewportUnits="Absolute">
<DrawingBrush.Drawing>
<GeometryDrawing>
<GeometryDrawing.Geometry>
<RectangleGeometry Rect="0,0,30,30"/>
</GeometryDrawing.Geometry>
<GeometryDrawing.Pen>
<Pen Brush="Gray" Thickness="1"/>
</GeometryDrawing.Pen>
</GeometryDrawing>
</DrawingBrush.Drawing>
</DrawingBrush>
</Canvas.Background>
<ItemsControl ItemsSource="{Binding TimeAxis}">
<ItemsControl.ItemsPanel>
<ItemsPanelTemplate>
<StackPanel Name="horizontalLabels" Orientation="Horizontal" />
</ItemsPanelTemplate>
</ItemsControl.ItemsPanel>
<ItemsControl.ItemTemplate>
<DataTemplate>
<TextBlock Text="{Binding}" Margin="0,0,3,0" Width="27" Background="Red" Height="Auto" >
</TextBlock>
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
</Canvas>
【问题讨论】:
-
@IDarkCoder 我认为他们希望数字适合一行而不改变容器的大小或文本的大小。
-
您需要增加容器的大小或减小字体的大小。如果您尝试强制以该大小写入文本,它将重叠到下一个容器上,这会更糟。最后一个选择是尝试一种不同的字体,自然更小而不减小实际字体大小
-
@IDarkCoder 我同意,不改变某些方面使其适合是不可能的。如果您对画布有大小限制,我会选择先更改字体大小。然后创建一个悬停,如果需要,将展开框以查看数据。
-
@Darnold 当然你也可以将
TextBlock的TextTrimming设置为CharacterEllipsis来表示某些部分被截断并添加带有完整字符串的工具提示。 -
@Darnold 我将其作为答案包含在内,希望对 OP 有所帮助。