2011-09-07 86 views
0

我想提出并排摘要列表的一面,所以我创建了一个小型的ItemsControl来实现这一目标:意外行为ItemsControl的模板/ ItemTemplate中

<ItemsControl x:Name="GRS"> 
     <ItemsControl.Template> 
      <ControlTemplate> 
       <StackPanel Orientation="Horizontal" Margin="10"> 
        <StackPanel Orientation="Vertical"> 
         <TextBlock Text="Round" FontSize="20" /> 
         <TextBlock Text="Food" FontSize="20" /> 
         <TextBlock Text="Harvest" FontSize="20" /> 
         <TextBlock Text="State" FontSize="20" /> 
         <TextBlock Text="Private" FontSize="20" /> 
         <TextBlock Text="Value" FontSize="20" /> 
         <TextBlock Text="Type" FontSize="20" /> 
        </StackPanel> 
        <ItemsPresenter /> 
       </StackPanel> 
      </ControlTemplate> 
     </ItemsControl.Template> 
     <ItemsControl.ItemTemplate> 
      <DataTemplate> 
       <Border Margin="10" BorderBrush="Black" BorderThickness="2"> 
        <StackPanel Orientation="Vertical"> 
         <TextBlock Text="{Binding Path=RoundNumber}" FontSize="20" /> 
         <TextBlock Text="{Binding Path=PlayerAndModusSetting.FoodCost}" FontSize="20" /> 
         <CheckBox IsChecked="{Binding Path=IsHarvest}" FontSize="20" /> 
         <TextBlock Text="{Binding Path=PlayerAndModusSetting.StateBuildProject}" FontSize="20" /> 
         <TextBlock Text="{Binding Path=PlayerAndModusSetting.PrivateBuildProject}" FontSize="20" /> 
         <TextBlock Text="{Binding Path=Value}" FontSize="20" /> 
         <TextBlock Text="{Binding Path=ShipType}" FontSize="20" /> 
        </StackPanel> 
       </Border> 
      </DataTemplate> 
     </ItemsControl.ItemTemplate> 
    </ItemsControl> 

当我设置的ItemsSource &运行,其结果是列表的方向是垂直的,而不是水平的。

Example of wrong behaviour

正如你所看到的,第一个是SIDEM的一面,但在那之后,它继续向下,我不知道为什么。

谢谢。

回答

-1

您的项目模板的父控件是一个StackPanel - 每个项目是一个StackPanel,包含一个StackPanel内 - 你需要,如果你想让它横向平铺您ItemsPresenter周围改变容器WrapPanel

例子:

   </StackPanel> 
       <WrapPanel> 
        <ItemsPresenter /> 
       </WrapPanel> 
      </StackPanel> 
+0

这是不正确的。同样的行为被实现(只是测试它)。此外,堆叠面板的方向设置为水平,这意味着它应该扩展水平而不是垂直(它为ItemTemplate中的整个内容所做的)。 – NKCSS