使用WrapPanel

时间:2011-12-29 06:43:51

标签: windows-phone-7 c#-4.0 silverlight-4.0

我必须将内容包装在堆栈面板中的文本块中。以下XAML代码是

        <ListBox.ItemTemplate>

            <DataTemplate>

                    <StackPanel Width="300">

                    <Image Height="160" HorizontalAlignment="Left" Margin="0,0,-400,0"  VerticalAlignment="Top" Width="175" Source="{Binding thumb}"/>
                    <!--ContentControl Width="150" Height="110" VerticalAlignment="Top" HorizontalAlignment="Left" Margin="0,0,-400,0" Content="{Binding Image}"/>-->
                    <TextBlock  TextWrapping="Wrap"  VerticalAlignment="Top" HorizontalAlignment="Left" Margin="190,-167,-200,0" Text="{Binding title}"/>
                    <TextBlock  TextWrapping="Wrap"  VerticalAlignment="Top" HorizontalAlignment="Left" Margin="190,-135,-200,0" Text="{Binding page}"/>


                    <TextBlock FontSize="15" TextWrapping="Wrap" Height="Auto" Margin="190,-95,-200,0" Text="{Binding Name}" />

                    </StackPanel>

            </DataTemplate>
        </ListBox.ItemTemplate    


   When i specify the width of the text block the text wrap works in the vertical and horizontal orientation.

           I want the text to wrap in the vertical view only and in the horizontal view the text should not wrap without mention the textblock width.

例如在垂直视图中,列表框宽度很小,因此文本应为:

           match is between India and
           pakistan

在水平视图中..我需要单行

匹配在印度和巴基斯坦之间。

提前致谢!

&GT;

1 个答案:

答案 0 :(得分:2)

 <DataTemplate>
      <Grid>
           <Grid.ColumnDefinitions>
                <ColumnDefinition Width="Auto" />
                <ColumnDefinition Width="*" />
           </Grid.ColumnDefinitions>
           <Image Grid.Column="0" ... />
           <StackPanel Grid.Column="1">
                <TextBlock TextWrapping="NoWrap" ... />
                <TextBlock TextWrapping="NoWrap" ... />
                <TextBlock TextWrapping="Wrap" ... />
           </StackPanel>
      </Grid>
 </DataTemplate>