How to use Horizontal Orientation in WP8 ListBox?

♀尐吖头ヾ 提交于 2019-12-24 17:16:28

问题


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).
i.e . 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??


回答1:


try to add this code in your listBox:

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

the oriention of items depends on ItemsPanel.




回答2:


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



来源:https://stackoverflow.com/questions/21695053/how-to-use-horizontal-orientation-in-wp8-listbox

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!