I have a particular unknown-depth model hierarchy which I want to present in a UI panel in a simplified form (no user interaction, no expand/collapse, just display parents and indent subtrees of children).
I have the following working fine as a TreeView
, but it's heavier than what I want. Similar to how you can replace ListBox
with ItemsControl
if you don't want the user-interaction features, is there some way to replace TreeView
with something else to get simplified UI and interaction? (I know, I could probably just template the TreeView
, but that doesn't seem like the right approach either.)
<HierarchicalDataTemplate x:Key="SubcomponentTemplate"
ItemsSource="{Binding Subcomponents}">
<app:ComponentInfoControl Component="{Binding}" Margin="2" />
</HierarchicalDataTemplate>
...
<TreeView ItemsSource="{Binding Subcomponents}"
ItemTemplate="{StaticResource SubcomponentTemplate}">
<TreeView.ItemContainerStyle>
<Style TargetType="{x:Type TreeViewItem}">
<Setter Property="IsExpanded" Value="True" />
</Style>
</TreeView.ItemContainerStyle>
</TreeView>
The data model is basically a Component
that contains a collection of Component
s called Subcomponents
, each of which can have zero or more subcomponents of their own.
I've tried using HeaderedItemsControl
in place of the TreeView
, or inside the template, but it doesn't seem to pick up the subcomponents that way. I must be missing something magic.