如何在WP8 ListBox中使用水平方向?

时间:2014-02-11 06:50:48

标签: c# xaml windows-phone

我正在使用以下xaml代码水平显示列表

<ListBox x:Name="List" HorizontalAlignment="Left" Height="429" Margin="18,83,0,0" VerticalAlignment="Top" Width="424" SelectionChanged="List_SelectionChanged_1">
            <ListBox.ItemTemplate>
                <DataTemplate>
                        <StackPanel Orientation="Horizontal" Width="420" Height="80">
                            <TextBox x:Name="tbName" IsHitTestVisible="False" Height="70" Background="Green" Foreground="White" FontSize="22" BorderThickness="0" Text="{Binding Name}" />
                        </StackPanel>
                </DataTemplate>
            </ListBox.ItemTemplate>
        </ListBox>

我想要的是:
在TextBlock穿过宽度之后,它应该放在下一行中(通常它应该像我们在纸上写的那样)。
即在我们到达 StackPanel 的末尾之前,我们将水平追加 TextBox ,但在到达 StackPanel 结束后,我们将放置下一个 TextBox 在下一行。)

我该怎么做?

2 个答案:

答案 0 :(得分:6)

尝试在listBox中添加此代码:

<ListBox.ItemsPanel>
   <ItemsPanelTemplate>
       <StackPanel Orientation="Horizontal"/>
   </ItemsPanelTemplate>
</ListBox.ItemsPanel>

项目的方向取决于ItemsPanel。

答案 1 :(得分:1)

这是名称空间:

xmlns:tlk="clr-namespace:Microsoft.Phone.Controls;assembly=Microsoft.Phone.Controls.Toolkit"

并且有如何使用它:

<ListBox.ItemsPanel>
    <ItemsPanelTemplate>
        <tlk:WrapPanel></tlk:WrapPanel>
    </ItemsPanelTemplate>
</ListBox.ItemsPanel> 

<强>记住
您必须参考:Microsoft.Phone.Controls.Toolkit.dll