Windows Phone 8中ListBox如何自动换行?

3

当第一行被占用时,我该如何使图片转到下一行?

以下是我的当前代码:

<Grid x:Name="ContentPanel" Grid.Row="1" Margin="12,0,12,0">
    <TextBlock Text="Picture" Style="{StaticResource PhoneTextNormalStyle}"/>
    <ListBox x:Name="picList" ScrollViewer.HorizontalScrollBarVisibility="Auto">
        <ListBox.ItemsPanel>
            <ItemsPanelTemplate>
                <StackPanel Orientation="Horizontal"/>
            </ItemsPanelTemplate>
        </ListBox.ItemsPanel>
        <ListBox.ItemTemplate>
            <DataTemplate>
                <StackPanel>
                    <Image Source="{Binding Picture}" Height="80" Width="80"/>
                </StackPanel>
            </DataTemplate>
        </ListBox.ItemTemplate>
    </ListBox>
</Grid>
1个回答

6

使用WrapPanel替代StackPanel。由于Windows Phone 8没有提供WrapPanel控件,因此需要使用Windows Phone Toolkit

<Grid x:Name="ContentPanel" Grid.Row="1" Margin="12,0,12,0">
    <TextBlock Text="Picture" Style="{StaticResource PhoneTextNormalStyle}"/>
    <ListBox x:Name="picList" ScrollViewer.HorizontalScrollBarVisibility="Auto">
        <ListBox.ItemsPanel>
            <ItemsPanelTemplate>
                <WrapPanel Orientation="Horizontal"
                           Width="300"
                           HorizontalAlignment="Left"
                           />
            </ItemsPanelTemplate>
        </ListBox.ItemsPanel>
        <ListBox.ItemTemplate>
            <DataTemplate>
                <StackPanel>
                    <Image Source="{Binding Picture}" Height="80" Width="80"/>
                </StackPanel>
            </DataTemplate>
        </ListBox.ItemTemplate>
    </ListBox>
</Grid>

WrapPanel 不存在。 - Alvin
抱歉,我没有看到你的问题被标记为Windows Phone。您可以从Windows Phone Toolkit中获取WrapPanel:https://phone.codeplex.com/ - Dirk Vollmar

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接