ListBox下一行自动在Windows Phone 8中

时间:2013-02-01 10:38:54

标签: c# xaml windows-phone-8

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

以下是我目前的代码:

<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 个答案:

答案 0 :(得分: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>