多列列表框

时间:2011-10-31 12:51:39

标签: silverlight windows-phone-7

我需要按以下格式创建一个列表框;

[x]    [x]   ^
[x]    [x]   |
[x]    [x]   | ----> this is a side scroll and the [x] are pictures
[x]    [x]   |

我该怎么办?这是我现在的代码。

      <controls:PanoramaItem Header="New one"  Name="Pan1" >
                <ListBox Margin="0,0,-12,0" x:Name="NewTitlesListBox" 
                         ItemsSource="{Binding NewPicturesLocal}" 
                         SelectionChanged="NewListBoxSelectionChanged">

                    <ListBox.ItemTemplate>
                        <DataTemplate>
                            <StackPanel Orientation="Horizontal" Margin="0,0,0,20">
   <Image  Width="110" CacheMode="BitmapCache" Source="{Binding ThumbURL}" 
                                    Margin="12,0,9,0"/>

                            </StackPanel>
                        </DataTemplate>
                    </ListBox.ItemTemplate>
                </ListBox>
            </controls:PanoramaItem>

结果:

[x]   ^
[x]   |
[x]   | ----> this is a side scroll and the [x] are pictures
[x]   |

我尝试使用Grid(添加更多列)和Data Templating,但没有找到解决方案。

2 个答案:

答案 0 :(得分:4)

使用Silverlight Toolkit中的WrapPanel将是我的问题的解决方案

      <controls:PanoramaItem Header="New one"  Name="Pan1" >
                <ListBox Margin="0,0,-12,0" x:Name="NewTitlesListBox" 
                         ItemsSource="{Binding NewPicturesLocal}" 
                         SelectionChanged="NewListBoxSelectionChanged">

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

                    <ListBox.ItemTemplate>
                        <DataTemplate>
                            <StackPanel Orientation="Horizontal" Margin="0,0,0,20">
   <Image  Width="110" CacheMode="BitmapCache" Source="{Binding ThumbURL}" 
                                    Margin="12,0,9,0"/>

                            </StackPanel>
                        </DataTemplate>
                    </ListBox.ItemTemplate>
                </ListBox>
            </controls:PanoramaItem>

答案 1 :(得分:2)

一个简单的解决方案是使用Silverlight Toolkit中的WrapPanel: WrapPanel for WP7。您必须为ListBox设置ItemsPanelTemplate才能使用WrapPanel。在我链接到的页面的评论中有一个例子。