简体   繁体   中英

How to use Horizontal Orientation in WP8 ListBox?

I'm using the following xaml code to display a list horizontally,

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

What I want exactly is:
after the TextBlock crosses the width it should be placed in the next line (Typically it should be like how we write in a paper).
ie . until we reach the end of the StackPanel we will append the TextBox horizontally, but after the end of the StackPanel is reached we will place the next TextBox in the next line).

How can i do it??

try to add this code in your listBox:

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

the oriention of items depends on ItemsPanel.

Here's the namespace:

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

and there is how to use it:

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

Remember
You must reference: Microsoft.Phone.Controls.Toolkit.dll

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM