0

特定のルールに従ってアイテムをグループ化するために、GroupStyleが定義されたItemsControlがあります。

コードビハインドから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>
4

1 に答える 1

1

を介してテンプレートを取得し、MainItemsControl.GroupStyle.HeaderTemplate を使用VisualTreeHelperしてテンプレート内の正しいコントロールを見つけます

于 2012-04-25T14:55:27.463 に答える