Xaml 项目控制包装

Xaml 项目控制包装,xaml,silverlight,itemscontrol,wrappanel,Xaml,Silverlight,Itemscontrol,Wrappanel,我有一个需要以以下方式显示的动态数据列表: 1 4 7 10 2 5 8 11 3 6 9 12 13 16 19 22 14 17 20 23 15 18 21 24 ... 但是,我的代码只迭代顶部部分,并在屏幕外运行。以下代码位于网格中。我做错了什么 <toolkit:WrapPanel Orientation="Vertical" Grid.Row="2" > <ItemsControl Item

我有一个需要以以下方式显示的动态数据列表:

1  4  7  10
2  5  8  11
3  6  9  12

13 16 19 22
14 17 20 23
15 18 21 24
...
但是,我的代码只迭代顶部部分,并在屏幕外运行。以下代码位于网格中。我做错了什么

          <toolkit:WrapPanel Orientation="Vertical" Grid.Row="2" >
                <ItemsControl ItemsSource="{Binding ImagingTypes, Mode=TwoWay}" 
                              Margin="5">
                    <ItemsControl.ItemsPanel>
                        <ItemsPanelTemplate>
                                <toolkit:WrapPanel Orientation="Vertical"/>
                        </ItemsPanelTemplate>
                    </ItemsControl.ItemsPanel>
                    <ItemsControl.ItemTemplate>
                        <DataTemplate>
                            <StackPanel Orientation="Horizontal" Margin="5,0,5,0">
                                <CheckBox IsChecked="{Binding IsSelected, Mode=TwoWay}" VerticalAlignment="Top" />
                                <TextBlock Grid.Column="1" Text="{Binding Description}" MaxWidth="150" TextWrapping="Wrap" />
                            </StackPanel>
                        </DataTemplate>
                    </ItemsControl.ItemTemplate>
                </ItemsControl>
            </toolkit:WrapPanel>

对不起。我的英语不是很好,所以我不能完全理解你的意思。但是,如果你想要如上所述的序列,并且想要保持项目的静态位置,可以使用UniformGrid。我希望这就是你要找的

以下是代码:

我做了一个listview示例

  <ListView x:Name="SharedSizeScopeListView">
        <ListView.ItemsPanel>
            <ItemsPanelTemplate >                   
                <UniformGrid IsItemsHost="True" Columns="4"/>
            </ItemsPanelTemplate>
        </ListView.ItemsPanel>
        <ListViewItem Content="1"/>
        <ListViewItem Content="4"/>
        <ListViewItem Content="7"/>
        <ListViewItem Content="10"/>

        <ListViewItem Content="2"/>
        <ListViewItem Content="5"/>
        <ListViewItem Content="8"/>
        <ListViewItem Content="11"/>

        <ListViewItem Content="3"/>                       
        <ListViewItem Content="6"/>                        
        <ListViewItem Content="9"/>                        
        <ListViewItem Content="12"/>

        <ListViewItem Content="13"/>
        <ListViewItem Content="16"/>
        <ListViewItem Content="19"/>
        <ListViewItem Content="22"/>

        <ListViewItem Content="14"/>
        <ListViewItem Content="17"/>
        <ListViewItem Content="20"/>
        <ListViewItem Content="23"/>

        <ListViewItem Content="15"/>                        
        <ListViewItem Content="18"/>                       
        <ListViewItem Content="21"/>                     
        <ListViewItem Content="24"/>

    </ListView>

我认为
WrapPanel
不支持这种分层包装。嵌套方法行不通——内部面板无法将其“剩余”项“转发”到外部面板

实现这一点的最简单方法取决于您是想要固定数量的列,还是想要适合容器大小。如果是前者,则可以使用
网格
连续填充其单元格(使用代码隐藏或行为),即(0,0),(0,1),(0,2),(1,0),…,(0,4),(0,5),(0,6),(1,4)

如果是后者——您希望继续水平布置项目,直到用完空间——那么可能需要一个。编写您自己的面板有一点学习曲线(您必须阅读Silverlight布局系统),但它给了您很大的灵活性