2016-07-25 71 views
0

一直在一點上的這項研究,但一直沒能解決這個問題:TextBlock的包裝(UWP)

我有一個GridView,這裏是它的所有代碼:

<GridView Name="NewsGrid" IsItemClickEnabled="True" ItemClick="NewsGrid_ItemClick"> 
    <GridView.ItemTemplate> 
      <DataTemplate x:DataType="data:News"> 
       <Grid Height="Auto" Margin="0" Width="440"> 
        <Grid.RowDefinitions> 
         <RowDefinition Height="Auto"/> 
         <RowDefinition Height="*"/> 
        </Grid.RowDefinitions> 
        <Image Source="{x:Bind Image}" 
         HorizontalAlignment="Center" 
         Stretch="UniformToFill" 
         Margin="5" 
         Height="247" 
         Width="440"/> 
        <TextBlock Text="{x:Bind Body}" 
          Foreground="SteelBlue" 
          Grid.Row="1" 
          Height="Auto" 
          HorizontalAlignment="Stretch" 
          Width="440" 
          Margin="5 0 5 0"/> 
       </Grid> 
      </DataTemplate> 
    </GridView.ItemTemplate> 
</GridView> 

我想要完成的是TextBlock如果文本的長度超過440像素,就會打包。上面的代碼沒有完成。給你一些視覺效果,這裏是從上面的代碼的結果:

enter image description here

所以這最後一句話是「通行證」,並要求你可以看到它只是不斷去。我只是想讓它在下面闖入一條新線。我怎樣才能做到這一點?我也嘗試將我的Grid換成StackPanel,但結果是一樣的。

更新1 新增TextWrapping="Wrap"TextBlock,視覺效果是這樣的:

enter image description here

最後一個字顯示不出來了,甚至沒有在同一條線上。

回答

3

TextWrapping="Wrap"添加到您的TextBlock

另外! 對於這種情況必須發生的行的定義:

<Grid.RowDefinitions> 
    <RowDefinition Height="*"/> 
    <RowDefinition Height="Auto"/> 
</Grid.RowDefinitions> 
+0

謝謝!我試過了,請參閱問題編輯。 – CStruggle

+0

你可以看到「通行證」不再顯示在線上,這意味着包裹工作。問題是你的TextBlock沒有足夠的垂直空間。 – AlexDrenea

+0

對,但不'Height =「自動」解決?父母「網格」是問題嗎?因爲我的父'Grid'也有'Height =「Auto」'。 – CStruggle

相關問題