I have a ItemsControl with HeaderedContentControl's as items. In this I now want to present only the headers of each HeaderedContentControl. Using the ItemsPresenter I get the default template which is currently showing both the header and the content. How can I get around this behaviour? Can I instruct the ItemsPresenter somehow to use a local template showing only headers? Ive tried adding a new template as resource to the ItemsPresenter but it is ignoring that...
0
votes
1 Answers
0
votes
So if I understand you correctly, you just want to show the header. I'm not exactly sure why you wouldn't just bind to the value of the header in an ItemsControl without the HeaderedContentControl. But you can just leave the ItemTemplate's DataTemplate blank.
So coming for this:
<ItemsControl ItemsSource="{Binding PersonList}">
<ItemsControl.ItemTemplate>
<DataTemplate>
<HeaderedContentControl>
<HeaderedContentControl.Header>
<TextBlock Text="{Binding PersonName}" Foreground="Blue" />
</HeaderedContentControl.Header>
<ItemsControl ItemsSource="{Binding FriendList}">
<ItemsControl.ItemTemplate>
<DataTemplate>
<TextBlock Text="{Binding Name}" />
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
</HeaderedContentControl>
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
You would do this:
<ItemsControl ItemsSource="{Binding PersonList}">
<ItemsControl.ItemTemplate>
<DataTemplate>
<HeaderedContentControl>
<HeaderedContentControl.Header>
<TextBlock Text="{Binding PersonName}" Foreground="Blue" />
</HeaderedContentControl.Header>
<ItemsControl ItemsSource="{Binding FriendList}">
<ItemsControl.ItemTemplate>
<DataTemplate /> <!-- Important change -->
</ItemsControl.ItemTemplate>
</ItemsControl>
</HeaderedContentControl>
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>