2012-04-25 12 views
0

特定のルールに従ってアイテムをグループ化するために定義されたGroupStyleを持つItemsControlがあります。コードビハインドから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を使用します
関連する問題