Note that there are some explanatory texts on larger screens.

plurals
  1. POColumn Header for a WPF TreeView
    primarykey
    data
    text
    <p>I am using the WPF TreeView to display some hierarchical information. Each item in the TreeView consists of several attributes, so I am using a Grid within my HierarchicalDataTemplate to display these attributes:</p> <pre><code>&lt;HierarchicalDataTemplate x:Key="ArtistTemplate" ItemsSource="{Binding XPath=Title}" ItemTemplate="{StaticResource TitleTemplate}"&gt; &lt;Grid&gt; &lt;Grid.ColumnDefinitions&gt; &lt;ColumnDefinition SharedSizeGroup="NameColumn" /&gt; &lt;ColumnDefinition SharedSizeGroup="GenreColumn" /&gt; &lt;ColumnDefinition SharedSizeGroup="BornColumn" /&gt; &lt;ColumnDefinition SharedSizeGroup="DiedColumn" /&gt; &lt;/Grid.ColumnDefinitions&gt; &lt;TextBlock Grid.Column="0" Text="{Binding XPath=@Name}" /&gt; &lt;TextBlock Grid.Column="1" Text="{Binding XPath=@Genre}" /&gt; &lt;TextBlock Grid.Column="2" Text="{Binding XPath=@Born}" /&gt; &lt;TextBlock Grid.Column="3" Text="{Binding XPath=@Died}" /&gt; &lt;/Grid&gt; &lt;/HierarchicalDataTemplate&gt; </code></pre> <p>This displays as a nice TreeView with 4 columns - so far so good! The only additional thing I need is a header above the TreeView that displays column names. The header column widths should be synchronized with TreeViewItems and also the header styles should be customizable. What's the easiest way to do this?</p> <p>P.S. I found two solutions that came close:</p> <p>1) A TreeListView <a href="http://www.codeproject.com/KB/WPF/wpf_treelistview_control.aspx" rel="noreferrer">here</a>, but this requires me to implement a custom interface (ITreeModel) to my model. Also the approach in this solution is to start with a ListView and to implement a RowExpander manually. In my case, the TreeView is sufficiently close to what I need, so I am hoping that putting a header on it should be very simple.</p> <p>2) A TreeListView <a href="http://blogs.windowsclient.net/ricciolocristian/archive/2008/03/22/a-complete-wpf-treelistview-control.aspx" rel="noreferrer">here</a>. This one indeed starts with a TreeView, but I can't figure out how to customize the header. I suspect that I have to customize the GridViewHeaderRowPresenter in the generic.xaml, but this element does not seem to have its own ControlTemplate.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload