2012-04-25 81 views
0

我有一個ItemsControl,其中定義了一個GroupStyle以便按照一定的規則對我的項目進行分組。從代碼隱藏中訪問GroupStyle的DataTemplate控件

我想從我的代碼隱藏中訪問GroupStyle的DataTemplate中的項目。這樣的事情可能嗎?

這是GroupStyle的定義;我想在它訪問無論是StackPanel的或不同的標籤:

<ItemsControl ItemsSource="{Binding Conversations}" ItemTemplate="{DynamicResource ConversationTemplate}" Margin="15,1,15,1" x:Name="MainItemsControl"> 
    <ItemsControl.ItemsPanel> 
     <ItemsPanelTemplate> 
      <WrapPanel Orientation="Horizontal"/> 
     </ItemsPanelTemplate> 
    </ItemsControl.ItemsPanel> 
    <ItemsControl.GroupStyle> 
     <GroupStyle> 
      <GroupStyle.HeaderTemplate> 
       <DataTemplate> 
        <Grid Margin="10, 20, -250, 8"> 
         <Grid.RowDefinitions> 
          <RowDefinition/> 
          <RowDefinition/> 
         </Grid.RowDefinitions> 
         <StackPanel x:Name="GroupStackPanel" Orientation="Horizontal" Grid.Row="0" Loaded="OnConversationGroupCreated" Tag="{Binding Name}"> 
          <Label x:Name="VolumeLabel" Style="{DynamicResource HighlightedMetadataStyle}" Content="{Binding Name.Volume}" Panel.ZIndex="3"/> 
          <Label x:Name="ActLabel" Style="{DynamicResource HighlightedMetadataStyle}" Margin="-16,0,0,0" Content="{Binding Name.Act}" Panel.ZIndex="2"/> 
          <Label x:Name="ChapterLabel" Style="{DynamicResource HighlightedMetadataStyle}" Margin="-16,0,0,0" Content="{Binding Name.Chapter}" Panel.ZIndex="1"/> 
         </StackPanel> 
         <Rectangle Height="1" Fill="#FFDDDDDD" Grid.Row="1" Margin="0,8,0,0"/> 
         <Rectangle Height="1" Fill="#FFEAEAEA" Grid.Row="1" Margin="0,9,0,0"/> 
        </Grid> 
       </DataTemplate> 
      </GroupStyle.HeaderTemplate> 
     </GroupStyle> 
    </ItemsControl.GroupStyle> 
</ItemsControl> 

回答

1

獲得通過MainItemsControl.GroupStyle.HeaderTemplate 模板然後用VisualTreeHelper找到模板中正確的控制

相關問題