<p>The company has the traditional complex organizational structure, defining the amount of levels using the letter 'n' rather than an actual number. I will try and express the structure I'm trying to achieve in mono-spaced font:  </p>

<pre><code>         Alice
 ,--------|-------,------,------,
Bob      Fred    Jack   Kim    Lucy
 |        |      
Charlie  Greg    
Darren   Henry
Eric
</code></pre>

<p>As you can see it's not symmetrical, as Jack, Kim and Lucy report to Alice but have no reports of their own.  </p>

<p>Using a <code>TreeView</code> with an <code>ItemsPanel</code> containing a <code>StackPanel</code> and <code>Orientation="Horizontal"</code> is <a href="http://www.codeproject.com/KB/WPF/CustomTreeViewLayout.aspx" rel="nofollow noreferrer">easy enough</a>, but this can result in a very large <code>TreeView</code> once some people have 20 others reporting to them! You can <a href="http://www.codeproject.com/KB/WPF/AdvancedCustomTreeViewLyt.aspx" rel="nofollow noreferrer">also use</a> <code>Triggers</code> to peek into whether a <code>TreeViewItem</code> has children with <code>Property="TreeViewItem.HasItems"</code>, but this is not in the same context as the before-mentioned <code>ItemsPanel</code>. <em>Eg: I can tell that Fred has reports, but not whether they have reports of their own.</em>  </p>

<p>So, can you conditionally format <code>TreeViewItems</code> to be Vertical if they have no children of their own?</p>

[{'answer_id': 69952, 'author': 'rudigrobler', 'author_id': 5147, 'author_profile': 'https://Stackoverflow.com/users/5147', 'pm_score': 2, 'selected': False, 'text': '<p>Josh Smith has a excecllent CodeProject article about TreeView. Read it <a href="http://www.codeproject.com/KB/WPF/AdvancedCustomTreeViewLyt.aspx" rel="nofollow noreferrer">here</a></p>\n'}, {'answer_id': 113120, 'author': 'Mark Glorie', 'author_id': 952, 'author_profile': 'https://Stackoverflow.com/users/952', 'pm_score': 1, 'selected': True, 'text': '<p>I did end up using tips from the linked article, which I\'d already read through but didn\'t think would help me.  </p>\n\n<p>The meat of it happens here, in a converter:  </p>\n\n<pre><code>&lt;ValueConversion(GetType(ItemsPresenter), GetType(Orientation))&gt; _\nPublic Class ItemsPanelOrientationConverter\nImplements IValueConverter\n\nPublic Function Convert(ByVal value As Object, ByVal targetType As System.Type, _\nByVal parameter As Object, ByVal culture As System.Globalization.CultureInfo) _\nAs Object Implements System.Windows.Data.IValueConverter.Convert\n\n    \'The \'value\' argument should reference an ItemsPresenter.\'\n    Dim itemsPresenter As ItemsPresenter = TryCast(value, ItemsPresenter)\n    If itemsPresenter Is Nothing Then\n        Return Binding.DoNothing\n    End If\n\n    \'The ItemsPresenter\'\'s templated parent should be a TreeViewItem.\'\n    Dim item As TreeViewItem = TryCast(itemsPresenter.TemplatedParent, TreeViewItem)\n    If item Is Nothing Then\n        Return Binding.DoNothing\n    End If\n\n    For Each i As Object In item.Items\n        Dim element As StaffMember = TryCast(i, StaffMember)\n        If element.IsManager Then\n            \'If this element has children, then return Horizontal\'\n            Return Orientation.Horizontal\n        End If\n    Next\n\n    \'Must be a stub ItemPresenter\'\n    Return Orientation.Vertical\n\nEnd Function\n</code></pre>\n\n<p>Which in turn gets consumed in a style I created for the TreeView:  </p>\n\n<pre><code>    &lt;Setter Property="ItemsPanel"&gt;\n        &lt;Setter.Value&gt;\n            &lt;ItemsPanelTemplate &gt;\n                &lt;ItemsPanelTemplate.Resources&gt;\n                    &lt;local:ItemsPanelOrientationConverter x:Key="conv" /&gt;\n                &lt;/ItemsPanelTemplate.Resources&gt;\n                &lt;StackPanel IsItemsHost="True" \n                            Orientation="{Binding   \n                            RelativeSource={x:Static RelativeSource.TemplatedParent}, \n                            Converter={StaticResource conv}}" /&gt;\n            &lt;/ItemsPanelTemplate&gt;\n        &lt;/Setter.Value&gt;\n    &lt;/Setter&gt;\n</code></pre>\n'}]
['https://Stackoverflow.com/questions/69928', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/952/']