title: Using A WrapPanel in a TreeView
body: <p>I want to display data with level of detail, so i use a TreeView, but each detail is quite short, so i would like to use a WrapPanel (horizontal) to have many details per line.</p>
  
  <p>Something like :</p>
  
  <ul>
  <li><p>This is an unexpanded item</p></li>
  <li><p>This is The Header of an expanded item</p>
  
  <p>Info 1   Info 2   Info 3   Info 4</p>
  
  <p>Info 5   Info 6   Info 7  </p></li>
  </ul>
  
  <p>So i tried defining TreeViewItem's Template but i could not get the wrappanel to
  wrap. I have only one info per line, when info's datatemplate width is 100 and TreeView
  is 500. i tried setting Width of WrapPanel, ItemsWidth, are other things with no success.</p>
  
  <p>Any idea ?</p>
  
  <p>EDIT : i finally got this to work with a 'simpler' solution. Still it seems that we
  have to define the WrapPanel's Width, which make the solution less generic. </p>
  
  <p>Here's the solution i came to : just defining, in a style, the ItemsPanel used in a
  TreeViewItem :</p>
  
  <pre><code>&lt;Style TargetType="TreeViewItem"&gt;
     &lt;Setter Property="ItemsPanel"&gt;
         &lt;Setter.Value&gt;
                &lt;ItemsPanelTemplate&gt;
                  &lt;WrapPanel  Orientation="Horizontal"      
                              Width="520"
                              HorizontalAlignment="Stretch" 
                              Margin="0" 
                              ScrollViewer.HorizontalScrollBarVisibility="Disabled" 
                              IsItemsHost="True"  
                      /&gt;
                &lt;/ItemsPanelTemplate&gt;
         &lt;/Setter.Value&gt;
     &lt;/Setter&gt;
  &lt;/Style&gt;
  </code></pre>
  
  <p>And i still let the not working solution here, for completeness sake.
  (Why wouldn't it work ???)</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="2" Width="500"&gt;
                      &lt;Grid.RowDefinitions&gt;
                          &lt;RowDefinition Height="Auto" /&gt;
                          &lt;RowDefinition Height="Auto" /&gt;
                      &lt;/Grid.RowDefinitions&gt;
  
                      &lt;ContentPresenter Name="PART_Header"                 
                                        ContentSource="Header"
                                        HorizontalAlignment="Center"
                                        VerticalAlignment="Center" /&gt;
  
      !!!! this is the wrapanel not wrapping 
                      &lt;ListBox     Name="AllItems"     Grid.Row="1"      &gt;
                          &lt;ListBox.ItemsPanel&gt;
                              &lt;ItemsPanelTemplate&gt;
                                  &lt;WrapPanel  Orientation="Horizontal"   /&gt;
                              &lt;/ItemsPanelTemplate&gt;
                          &lt;/ListBox.ItemsPanel&gt;
                          &lt;ItemsPresenter   /&gt;
                      &lt;/ListBox&gt;
  
                  &lt;/Grid&gt; 
  
                  &lt;ControlTemplate.Triggers&gt;
                      &lt;Trigger Property="IsExpanded" Value="False"&gt;
                          &lt;Setter
                                         TargetName="AllItems"
                                          Property="Visibility"                     
                                            Value="Collapsed" /&gt;
                    &lt;/Trigger&gt;
                  &lt;/ControlTemplate.Triggers&gt;
              &lt;/ControlTemplate&gt;
          &lt;/Setter.Value&gt;
      &lt;/Setter&gt;
  &lt;/Style&gt;
  </code></pre>