Onl*_*ere 11 wpf xaml panel datatemplate itemscontrol
这是XAML标记:
<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>
Run Code Online (Sandbox Code Playgroud)
这就是它的样子:

我希望这些项目水平显示并在到达StackPanel边缘时向下流动.
目前看来,我的DataContext集合中的每个项目都在创建自己的StackPanel,所以这不是我想要的.
有什么建议?
Gay*_*Fow 16
如果将ItemsPanel模板更改为WrapPanel或水平StackPanel,则可以实现您之后的效果......
<ItemsControl>
<ItemsControl.ItemsPanel>
<ItemsPanelTemplate>
<WrapPanel Orientation="Horizontal"/>
</ItemsPanelTemplate>
</ItemsControl.ItemsPanel>
<ItemsControl.ItemTemplate>
<!--other stuff here-->
</ItemsControl.ItemTemplate>
</ItemsControl>
Run Code Online (Sandbox Code Playgroud)
在此片段中,ItemsPanel设置为水平定向的WrapPanel.ItemTemplate将包含您已经拥有的绑定和样式......