2011-11-05 46 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属性堆栈面板,然后尝试。