2016-08-01 86 views
0

我有一個嵌套的ItemsControl。我的數據結構是一個Campaigns的ObservableCollection,它由一個Campaign類和一個數據計數(總計,分配,未分配,關閉)的observableCollection組成。我需要的是以下幾點:嵌套ItemsControl方向

CAMPAIGN.NAME 
    TOTAL  UNASSIGNED  ASSIGNED  CLOSED 
CAMPAIGN.NAME 
    TOTAL  UNASSIGNED  ASSIGNED  CLOSED 

我能拿到這個第一部分,但由於某種原因,它不會兌現第二ItemsControl的方向。我錯過了什麼?我的XAML是:

<ItemsControl x:Name="icCampaignChicklets" ItemsSource="{Binding CampChicks}" Grid.Row="1"> 
     <ItemsControl.ItemsPanel> 
      <ItemsPanelTemplate> 
       <StackPanel Orientation="Vertical" /> 
      </ItemsPanelTemplate> 
     </ItemsControl.ItemsPanel> 
     <ItemsControl.ItemTemplate> 
      <DataTemplate> 
       <Grid x:Name="gridContent"> 
        <Grid.RowDefinitions> 
         <RowDefinition Height="20" /> 
         <RowDefinition Height="*" /> 
        </Grid.RowDefinitions> 
        <TextBlock x:Name="CampaignHeader" Height="20" Text="{Binding Path=Campaign.Name}" Grid.Row="1" VerticalAlignment="Top" TextWrapping="Wrap" HorizontalAlignment="Left" /> 
        <StackPanel Grid.Row="1" Orientation="Horizontal" Margin="10"> 
         <ItemsControl x:Name="icChicklets" ItemsSource="{Binding Path=Data}"> 
          <ItemsControl.ItemTemplate> 
           <DataTemplate> 
            <Border Width="150" Height="140" Background="{Binding Background}" Cursor="Hand" 
            MouseLeftButtonDown="Chicklet_MouseLeftButtonDown" 
            > 
             <Grid x:Name="gridContent" Margin="8,4"> 
              <TextBlock Text="{Binding Caption}" Foreground="White" FontSize="17" /> 
              <TextBlock Text="{Binding CountCaption, Mode=OneWay}" Foreground="White" FontSize="45" VerticalAlignment="Center" HorizontalAlignment="Right" Margin="7" /> 
              <TextBlock Text="Ú" Foreground="#99ffffff" FontSize="30" VerticalAlignment="Bottom" HorizontalAlignment="Right" Margin="3,5" FontFamily="Wingdings 3" /> 
             </Grid> 
            </Border> 
           </DataTemplate> 

          </ItemsControl.ItemTemplate> 
         </ItemsControl> 
        </StackPanel> 
       </Grid> 
      </DataTemplate> 
     </ItemsControl.ItemTemplate> 
    </ItemsControl> 

回答

0

如果你想改變一個ItemsControl的內容定位,設置其ItemsPanel屬性,像這樣:

<ItemsControl 
    ...attributes... 
    > 
    <ItemsControl.ItemsPanel> 
     <ItemsPanelTemplate> 
      <StackPanel Orientation="Horizontal" /> 
     </ItemsPanelTemplate> 
    </ItemsControl.ItemsPanel> 
</ItemsControl> 

在水平定向父結束語StackPanel只會水平排列它和它的兄弟姐妹,但在這種特殊情況下,它沒有兄弟姐妹。

+0

謝謝!我早些時候嘗試過,但Intellisense瘋了。那時我一定有其他的瘋狂。 –