我有以下XAML,它在网格中显示一个文本块。问题是它只是延伸出来,甚至比窗户宽度还要大。
<Grid Background="Gray">
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto" />
<ColumnDefinition Width="Auto" />
</Grid.ColumnDefinitions>
<Label Grid.Row="1" Grid.Column="0" Padding="0" FontWeight="Bold" Margin="0,0,5,0">Description:</Label>
<TextBlock Grid.Row="1" Grid.Column="1" Text="{Binding Description}" TextWrapping="Wrap" VerticalAlignment="Stretch" HorizontalAlignment="Stretch" />
</Grid>
答案 0 :(得分:8)
您需要第二列的restrict the width
来进行文本换行 -
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto" />
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>