StackPanel 中的文本不换行 (wp7) [英] Text in StackPanel doesn't wrap (wp7)

查看:23
本文介绍了StackPanel 中的文本不换行 (wp7)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的文字换行有问题.如果没有 StackPanel,这个 TextBlock 可以工作,但我需要在文本之前放小图片.另外我没有两列(前三行只需要一列)

I have problem with text wrapping. Without StackPanel this TextBlock works, but i need to put small picture before text. Also I don't have two columns for this (i need only one column for first three rows)

<ListBox.ItemTemplate>
    <DataTemplate>  
        <Grid>
             <Grid.RowDefinitions >
                 <RowDefinition Height="60"/>
                 <RowDefinition Height="170"/>
                 <RowDefinition Height="50"/>
                 <RowDefinition Height="Auto"/>
                 <RowDefinition Height="Auto"/>
                 <RowDefinition Height="Auto"/>
            </Grid.RowDefinitions>

             <TextBlock Grid.Row="0"></TextBlock>                                   
             <TextBlock Grid.Row="1"></TextBlock>                                   
             <TextBlock Grid.Row="2"></TextBlock>                                   
             <StackPanel Grid.Row="3" Orientation="Horizontal">
                  <Image  Source="Picture.png" MaxHeight="20" MaxWidth="40" HorizontalAlignment="Center" Margin="0,20,0,0" />
                  <TextBlock Text="Long long long text from Binding" FontSize="25" HorizontalAlignment="Center" TextAlignment="Center" TextWrapping="Wrap" VerticalAlignment="Bottom" Padding="20,10,0,0"  />
             </StackPanel>
         </Grid>
    </DataTemplate>
</ListBox.ItemTemplate>

推荐答案

一个 StackPanel 将根据 Orientation 为其组件赋予无限的高度或宽度.

A StackPanel will give its components infinite height or width depending on the Orientation.

如果我查看您的 XAML,我建议在网格中使用两列,并将图像放在左侧:

If I look at your XAML I would suggest to use two columns in the grid, and put the image on the left side:

<ListBox.ItemTemplate>
    <DataTemplate>
        <Grid>
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="40" />
                <ColumnDefinition Width="*" />
            </Grid.ColumnDefinitions>
            <Grid.RowDefinitions >
                <RowDefinition Height="60"/>
                <RowDefinition Height="170"/>
                <RowDefinition Height="50"/>
                <RowDefinition Height="Auto"/>
                <RowDefinition Height="Auto"/>
                <RowDefinition Height="Auto"/>
            </Grid.RowDefinitions>

            <TextBlock Grid.Row="0" Grid.ColumnSpan="2"></TextBlock>
            <TextBlock Grid.Row="1" Grid.ColumnSpan="2"></TextBlock>
            <TextBlock Grid.Row="2" Grid.ColumnSpan="2"></TextBlock>
            <Image Grid.Row="3" Source="Picture.png" MaxHeight="20" HorizontalAlignment="Center" Margin="0,20,0,0" />
            <TextBlock Grid.Column="1" Grid.Row="3" Text="Long long long text from Binding" FontSize="25" 
                        HorizontalAlignment="Center" TextAlignment="Center" TextWrapping="Wrap" 
                        VerticalAlignment="Bottom" Padding="20,10,0,0"  />
        </Grid>
    </DataTemplate>
</ListBox.ItemTemplate>

注意第一个文本框上的 Grid.ColumnSpan,这将使它们跨越网格的整个宽度,而不仅仅是第一列.

Notice Grid.ColumnSpan on the first textboxes, this will span them over the entire width of the grid, not just the first column.

这篇关于StackPanel 中的文本不换行 (wp7)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆