9

我有以下 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>
4

1 回答 1

12

您需要restrict the width在第二列中进行文本换行 -

<Grid.ColumnDefinitions>
        <ColumnDefinition Width="Auto" />
        <ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>
于 2012-11-22T18:22:12.707 回答