GridViewItem高度调整为Windows Phone 8.1中的内容

时间:2015-07-01 14:16:11

标签: c# wpf gridview windows-phone-8.1

我正在使用GridView来显示一些产品。 当我设置DataTemplate时,我使用带有静态值的Width和Height,并为我想要显示的数据定义一些行。

 <Grid Width="97" Height="180"">
       <Grid.RowDefinitions>
       <RowDefinition Height="80"/>
       <RowDefinition Height="20"/>
       <RowDefinition Height="*"/>

第一行是80x80的图像,第二行是价格。到目前为止,非常好。

然后我面临的问题是,即使最后一行显示的数据(带有 TextBlock 的产品名称)只有一行,GridViewItem也会获取定义的值高度属性。 有没有办法在TextBlock的文本上调整高度。我尝试将“高度”设置为“自动”,完全不包括“网格”和“文本块”,但文本未显示在屏幕上。

1 个答案:

答案 0 :(得分:0)

我有一种感觉,你想要的是要包裹的文字。您可以通过设置要包装的文本来实现此目的,如下面演示的代码所示:

<Grid>
    <Grid.RowDefinitions>
        <RowDefinition Height="80"/>
        <RowDefinition Height="20"/>
        <RowDefinition Height="Auto"/>
    </Grid.RowDefinitions>

    <Grid Grid.Row="0" Background="Red" />
    <Grid Grid.Row="1" Background="Blue" />
        <TextBlock Grid.Row="2" TextWrapping="Wrap" Text="This is some text which will not fall off the edge because it is set to wrap around, and will continue filling down until the end of the screen because the grid is set to auto" />
</Grid>