title: Always show selected item in TreeView
body: <p>Is there a way to have the selected item of a <code>TreeView</code> always shown? In other words, to disallow collapsing of the nodes that contain the selected item?</p>
  
  <p>I have a <code>TreeView</code> with a hierarchical data template</p>
  
  <pre><code>&lt;TreeView ItemsSource="{Binding Properties, Mode=OneWay}"&gt;
      &lt;TreeView.Resources&gt;
          &lt;ResourceDictionary&gt;
              &lt;ResourceDictionary.MergedDictionaries&gt;
                  &lt;ResourceDictionary Source="ExpanderTreeViewItemStyle.xaml"/&gt;
              &lt;/ResourceDictionary.MergedDictionaries&gt;
              &lt;HierarchicalDataTemplate DataType="{x:Type viewModel:ComplexProperty}" ItemsSource="{Binding Properties, Mode=OneWay}"&gt;
                  &lt;StackPanel Orientation="Horizontal"&gt;
                      &lt;TextBlock Text="{Binding DisplayName}"/&gt;
                  &lt;/StackPanel&gt;
              &lt;/HierarchicalDataTemplate&gt;
              &lt;DataTemplate DataType="{x:Type viewModel:SimpleProperty}"&gt;
                  &lt;StackPanel Orientation="Horizontal"&gt;
                      &lt;TextBlock Text="{Binding DisplayName, Mode=OneWay}"/&gt;
                      &lt;TextBlock Text="{Binding Value, Mode=OneWay}"/&gt;
                  &lt;/StackPanel&gt;
              &lt;/DataTemplate&gt;
          &lt;/ResourceDictionary&gt;
      &lt;/TreeView.Resources&gt;
  &lt;/TreeView&gt;
  </code></pre>
  
  <p>styled so that only the nodes without children are focusable (the container items are templated to use an expander instead of the usual tree with +/- buttons, but that shouldn't make a difference). </p>
  
  <p>When a leaf node is selected, how do I prevent the containing node(s) from being wrapped, hiding the selected node?</p>
  
  <p>Here's the style for reference</p>
  
  <pre><code>&lt;Style TargetType="TreeViewItem"&gt;
      &lt;Setter Property="Template"&gt;
          &lt;Setter.Value&gt;
              &lt;ControlTemplate TargetType="TreeViewItem"&gt;
                  &lt;Grid Margin="8,4"&gt;
                      &lt;Border Name="ItemBorder" BorderBrush="Gray" BorderThickness="0.3" Padding="6" SnapsToDevicePixels="True"&gt;
                          &lt;Grid&gt;
                              &lt;Expander Name="StructuredItemExpander"&gt;
                                  &lt;Expander.Header&gt;
                                      &lt;ContentPresenter ContentSource="Header"/&gt;
                                  &lt;/Expander.Header&gt;
                                  &lt;ItemsPresenter/&gt;
                              &lt;/Expander&gt;
  
                              &lt;ContentPresenter Name="AtomicItemContents" ContentSource="Header" Visibility="Collapsed"/&gt;
                          &lt;/Grid&gt;
                      &lt;/Border&gt;
                  &lt;/Grid&gt;
                  &lt;ControlTemplate.Triggers&gt;
                      &lt;Trigger Property="TreeViewItem.HasItems" Value="False"&gt;
                          &lt;Setter TargetName="StructuredItemExpander" Property="Visibility" Value="Collapsed"/&gt;
                          &lt;Setter TargetName="AtomicItemContents" Property="Visibility" Value="Visible"/&gt;
                          &lt;Setter TargetName="ItemBorder" Property="BorderBrush" Value="Transparent"/&gt;
                          &lt;Setter Property="Focusable" Value="True"/&gt;
                      &lt;/Trigger&gt;
                      &lt;Trigger Property="IsSelected" Value="True"&gt;
                          &lt;Setter TargetName="ItemBorder" Property="BorderBrush" Value="Aqua"/&gt;
                      &lt;/Trigger&gt;
                  &lt;/ControlTemplate.Triggers&gt;
              &lt;/ControlTemplate&gt;
          &lt;/Setter.Value&gt;
      &lt;/Setter&gt;
  
      &lt;Setter Property="Focusable" Value="False"/&gt;
  
      &lt;Setter Property="ItemsPanel"&gt;
          &lt;Setter.Value&gt;
              &lt;ItemsPanelTemplate&gt;
                  &lt;StackPanel IsItemsHost="True" Orientation="Vertical"/&gt;
              &lt;/ItemsPanelTemplate&gt;
          &lt;/Setter.Value&gt;
      &lt;/Setter&gt;
  &lt;/Style&gt;
  </code></pre>