2011-11-05 47 views
0

In Orientation =「Horizo​​ntal」TextWrapping不能在代碼下面工作,請檢查錯誤告訴我。wp7 TextWrapping無法正常工作?

mycode的:

<StackPanel> 
         <StackPanel Orientation="Horizontal" Width="400"> 
          <TextBlock Text="dfgdfdgdfgfdgdfg" Foreground="AntiqueWhite" FontSize="30" TextWrapping="Wrap"/> 
          <TextBlock Text=" vs " FontSize="30" Foreground="White" TextWrapping="Wrap"/> 
          <TextBlock Text="Indiaafda (text)" Foreground="Bisque" FontSize="30" TextWrapping="Wrap"/> 
         </StackPanel> 

       </StackPanel> 

我wnat這樣的:

South AfricaTeamPlayed vs west 
Indies (test) 

但輸出顯示此,

South AfricaTeamPlayed vs west 
        Indies (test) 

感謝

回答

4

您應該使用Grid研究所ead of StackPanel

這樣的事情,

<Grid Width="400" Margin="40,0"> 
     <Grid.ColumnDefinitions> 
      <ColumnDefinition /> 
      <ColumnDefinition Width="Auto" /> 
      <ColumnDefinition /> 
     </Grid.ColumnDefinitions> 
     <TextBlock Text="dfgdfdgdfgfdgdfg" Foreground="AntiqueWhite" FontSize="30" TextWrapping="Wrap"/> 
     <TextBlock Text=" vs " FontSize="30" Foreground="White" TextWrapping="Wrap" Grid.Column="1"/> 
     <TextBlock Text="Indiaafda (text)" Foreground="Bisque" FontSize="30" TextWrapping="Wrap" Grid.Column="2"/> 
    </Grid> 

我可能會重新設計整個事情是這樣的,

<Grid> 
     <Grid.RowDefinitions> 
      <RowDefinition Height="Auto"/> 
      <RowDefinition/> 
     </Grid.RowDefinitions> 
     <Grid d:LayoutOverrides="Height" Margin="40,0"> 
      <Grid.ColumnDefinitions> 
       <ColumnDefinition /> 
       <ColumnDefinition Width="Auto" /> 
       <ColumnDefinition /> 
      </Grid.ColumnDefinitions> 
      <TextBlock Text="dfgdfdgdfgfdgdfg" Foreground="AntiqueWhite" FontSize="30" TextWrapping="Wrap"/> 
      <TextBlock Text=" vs " FontSize="30" Foreground="White" TextWrapping="Wrap" Grid.Column="1" VerticalAlignment="Center" HorizontalAlignment="Center"/> 
      <TextBlock Text="Indiaafda (text)" Foreground="Bisque" FontSize="30" TextWrapping="Wrap" Grid.Column="2"/> 
     </Grid> 
     <Grid Grid.Row="1"> 
      <TextBlock HorizontalAlignment="Center" TextWrapping="Wrap" Text="where other stuff goes" VerticalAlignment="Center"/> 
     </Grid> 
    </Grid> 

UPDATE

<Grid VerticalAlignment="Top" Margin="40,0"> 
     <TextBlock Foreground="AntiqueWhite" FontSize="30" TextWrapping="Wrap"> 
      <Run Text="south africa"/> 
      <Run Text="vs"/> 
      <Run Text="windows phone"/> 
     </TextBlock> 
    </Grid> 
+0

dfgdfdgdfgfdgdfg這句話也是一個接一個分開的。我想繼續textBlock這樣,dfgdfdgdfgfdgdfg vs Indiaafda(文本)它會來兩行。在tyhis代碼第一句顯示兩行,第二句顯示兩行。 – Jeeva

+0

所以你想在一行中的第一個文本,並在第二行中包裝第二個文本?嘗試將第一個ColumnDefinition改爲自動寬度。 –

+0

我第一次來到正確的第三個測試顯示垂直不是第二行。 – Jeeva

0

刪除Width屬性堆棧面板,然後嘗試。