wp7 TextWrapping无法正常工作?

时间:2011-11-05 06:21:48

标签: windows-phone-7 textblock

在Orientation =“水平”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>

我想这样:

South AfricaTeamPlayed vs west
Indies (test)

但输出会显示,

South AfricaTeamPlayed vs west
                  Indies (test)

由于

2 个答案:

答案 0 :(得分:4)

您应该使用Grid代替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>

<强>更新

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

答案 1 :(得分:0)

删除Stack Panel的Width属性,然后尝试。