简体   繁体   English

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

[英]GridViewItem height adjust to content in Windows Phone 8.1

I am using a GridView to display some products. 我正在使用GridView来显示一些产品。 When I set the DataTemplate I use Width and Height with static values and define some rows for the data I want to display. 设置DataTemplate时,我将Width和Height使用静态值,并为要显示的数据定义一些行。

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

The first row is for a 80x80 image and the second for the price.So far, so good. 第一行用于80x80图像,第二行用于价格。到目前为止,效果很好。

Then I face the problem that even if the data shown (with the name of the product) in the last row, with a TextBlock , is just one line, the GridViewItem takes the value defined from the height property. 然后,我面临的问题是,即使最后一行显示的数据(带有产品名称)(带有TextBlock )只是一行,GridViewItem也会采用height属性定义的值。 Is there a way for the height to adjust on TextBlock's Text. 有没有一种方法可以在TextBlock的Text上调整高度。 I tried setting Height to Auto, not including at all for the Grid and the TextBlock but then the text is not appearing whole on the screen. 我尝试将“高度”设置为“自动”,而不完全包含“网格”和“文本块”,但是文本在屏幕上并未完整显示。

I have a feeling what you want is the text to wrap around. 我觉得您想要的是要环绕的文字。 You can achieve this by setting the text to wrap, like in the code demonstrated below: 您可以通过将文本设置为自动换行来实现此目的,如下面的代码所示:

<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>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM