C# 多列stackpanel或备选方案

C# 多列stackpanel或备选方案,c#,xaml,stackpanel,windows-store,C#,Xaml,Stackpanel,Windows Store,我有以下XAML代码: <StackPanel Background="White" Margin="267,207,0,44" Grid.ColumnSpan="2"> <ScrollViewer Margin="30,30,0,30" Height="444"> <ItemsControl Name="ListCountries"> <ItemsControl.ItemsPanel>

我有以下XAML代码:

 <StackPanel Background="White" Margin="267,207,0,44" Grid.ColumnSpan="2">
   <ScrollViewer Margin="30,30,0,30" Height="444">
      <ItemsControl Name="ListCountries">
         <ItemsControl.ItemsPanel>
            <ItemsPanelTemplate>
               <StackPanel Orientation="Horizontal" />
            </ItemsPanelTemplate>
         </ItemsControl.ItemsPanel>
         <ItemsControl.ItemTemplate>
            <DataTemplate>
               <StackPanel Margin="0,0,10,0" Width="100">
                  <TextBlock Text="{Binding Key}" Foreground="Red" />
                  <ItemsControl ItemsSource="{Binding}">
                     <ItemsControl.ItemTemplate>
                        <DataTemplate>
                           <StackPanel Margin="0,10,0,0">
                              <TextBlock TextWrapping="Wrap" Text="{Binding title}" Foreground="Black" />
                              <TextBlock TextWrapping="Wrap" Text="{Binding desc}" Foreground="Gray" />
                           </StackPanel>
                        </DataTemplate>
                     </ItemsControl.ItemTemplate>
                  </ItemsControl>
               </StackPanel>
            </DataTemplate>
         </ItemsControl.ItemTemplate>
      </ItemsControl>
   </ScrollViewer>
</StackPanel>

我使用IEnumerable>设置名为ListCountries的itemsControl的itemSource,它打印标题列表,然后是OtherClass的对象列表

我的问题是,填充的列有时大于它们插入到的Stackpanel的高度,我希望能够将我的内部列表拆分为列

如图所示,比利时被分成两列
现在我所有的国家/地区都是垂直滚动的单列。

您应该使用
网格视图来进行此操作。下面是一些从VisualStudio中的
Grid
应用程序稍微修改的代码

    <GridView
        x:Name="itemGridView"
        Grid.RowSpan="2"
        Padding="116,137,40,46"
        ItemsSource="{Binding Source={StaticResource groupedItemsViewSource}}"
        SelectionMode="None"
        Height="600">
        <GridView.ItemTemplate>
            <DataTemplate>
                <Grid HorizontalAlignment="Left" Width="200">
                    <TextBlock Text="{Binding Description}" Foreground="{ThemeResource ListViewItemOverlayForegroundThemeBrush}" Style="{StaticResource TitleTextBlockStyle}" Height="60" Margin="15,0,15,0"/>                       
                </Grid>
            </DataTemplate>
        </GridView.ItemTemplate>
        <GridView.GroupStyle>
            <GroupStyle>
                <GroupStyle.HeaderTemplate>
                    <DataTemplate>
                        <TextBlock Text="{Binding Title}" Style="{StaticResource SubheaderTextBlockStyle}" TextWrapping="NoWrap" />
                    </DataTemplate>
                </GroupStyle.HeaderTemplate>
            </GroupStyle>
        </GridView.GroupStyle>
    </GridView>

这是一个屏幕截图,上面有一些示例数据


在可视化您想要的东西时遇到困难,您能提供一个可视化的解决方案吗?那应该是小菜一碟。我编辑了我的帖子,希望它能变得更清晰一些,这样你就会希望(例如)比利时的名单上的所有信息都在同一列中,这样所有信息都有2列,而不是4列?同一列中的所有信息都是我现在拥有的,每个国家一列:),如果它到达底部,我想把它分开。如果它通过stackpanel限制,我现在看到的内容将向下滚动,这可以帮助您处理多列