【问题标题】:wp7 TextWrapping not working?wp7 TextWrapping 不起作用?
【发布时间】:2011-11-09 18:54:06
【问题描述】:

在 Orientation="Horizo​​ntal" TextWrapping 在代码下面不起作用请检查错误告诉我。

我的代码:

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

谢谢

【问题讨论】:

    标签: windows-phone-7 textblock


    【解决方案1】:

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

    【讨论】:

    • dfgdfdgdfgfdgdfg 这句话也是一一拆分的。我想继续这样的textBlock,dfgdfdgdfgfdgdfg vs Indiaafda(文本)它将出现两行。在 tyhis 代码中,第一句显示两行,第二句显示两行。
    • 所以你想要第一个文本在一行中,第二个文本在两行中?尝试将第一个 ColumnDefinition 更改为 Auto width。
    • 我第一个文本正确第三个测试显示垂直而不是第二行。
    • 你的意思是你想让第三个一直到第二行的左边?你能让你的问题更清楚吗?我迷路了……
    • 我正在创建 3 个文本块,其中三个显示一个接一个的效果。但是第三个到达终点时它不会出现在第二行。它需要一些宽度数据,仅显示特定宽度。
    【解决方案2】:

    删除堆栈面板的宽度属性,然后尝试。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-05-18
      • 2023-03-04
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多