2012-01-07 70 views
10

这里面是XAML标记:显示项目的集合ItemsControl的水平

 <ScrollViewer Grid.Column="1" Grid.Row="2" HorizontalScrollBarVisibility="Disabled" Width="990"> 
      <StackPanel Margin="50 0 0 40">      
       <ItemsControl x:Name="streamList" ItemsSource="{Binding StreamInformations}"> 
        <ItemsControl.ItemTemplate> 
         <DataTemplate> 
          <StackPanel Margin="10" Orientation="Horizontal" > 
           <StackPanel Orientation="Horizontal"> 
            <Image Source="{Binding ImageUrl}" Height="60" /> 
            <StackPanel Margin="10 0 0 0" VerticalAlignment="Center"> 
             <TextBlock Foreground="Black" Text="{Binding ChannelName}" FontSize="12" /> 
             <TextBlock Foreground="#999" Text="{Binding PlayerName}" FontSize="10" /> 
             <TextBlock Foreground="#999" Text="{Binding ViewCount}" FontSize="10" /> 
            </StackPanel>           
           </StackPanel>         
          </StackPanel> 
         </DataTemplate> 
        </ItemsControl.ItemTemplate> 
       </ItemsControl> 
      </StackPanel> 
     </ScrollViewer> 

,这是它的外观:

enter image description here

我想这些项目出现当它到达StackPanel的边缘时水平和向下流动。

看来,目前,我的DataContext集合中的每个项目都创建它自己的StackPanel,所以这不是我想要的。

有什么建议吗?

+4

如果此问题的唯一答案适用于您,然后接受它。如果没有,请提供反馈意见,说明为什么它不适合您的问题。答案已经为其他一些人起作用了,包括我自己。 – Xtr 2013-07-18 08:45:22

回答

16

如果更改ItemsPanel模板,无论是WrapPanel或水平StackPanel中,你可以实现你后的效果......

<ItemsControl> 
    <ItemsControl.ItemsPanel> 
     <ItemsPanelTemplate> 
      <WrapPanel Orientation="Horizontal"/> 
     </ItemsPanelTemplate> 
    </ItemsControl.ItemsPanel> 
    <ItemsControl.ItemTemplate> 
     <!--other stuff here--> 
    </ItemsControl.ItemTemplate> 
</ItemsControl> 

在这个片段中,ItemsPanel设置为水平方向的一个WrapPanel。 ItemTemplate将包含您已具有的装订和样式...