我在试图弄清楚如何使文本块换行时发现了这个问题,当该文本块是 ItemsControl 中每个项目的模板时。
我的原始模板:
<ItemsControl.ItemTemplate>
<DataTemplate>
<Grid>
<TextBlock Padding="2" x:Name="SummaryRow" Text="{Binding}" TextWrapping="Wrap" />
</Grid>
</DataTemplate>
</ItemsControl.ItemTemplate>
为了使文本真正换行,我必须用边框包围文本块。我相信其他容器也可以工作。
这是为什么呢?(顺便说一句,我应该提到ItemsControl在ScrollViewer中)
对于要换行的文本,您需要restrict the size of the textBlock
,以便在文本超过该限制限制时换行。但是由于您的textBlock在外面有scrollViewer,因此它的大小没有限制,因此没有换行。您需要设置HorizontalScrollBarVisbility to Collapsed or Hidden
以限制文本的大小和换行。