使TextBlock在Grid列中自动换行

9
我有以下的XAML代码,它在一个grid中展示了一个textblock。问题是它会不断地拉伸,甚至还可能比窗口更宽。
<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>
1个回答

12

您需要限制第二列的宽度,以使文本换行 -

<Grid.ColumnDefinitions>
        <ColumnDefinition Width="Auto" />
        <ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>

谢谢,你的示例有效。结果发现我的问题是错误的,真正的问题在于DataGrid.RowDetailsTemplate以及其中的内容。也许你能回答这个问题:http://stackoverflow.com/questions/13518476/make-textblock-wrap-in-datagrid-rowdetailstemplate - Drahcir
2
您所发布的问题页面不可用。 - Rohit Vats

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接