title: How to make text wrap for a TreeView in wpf
body: <p>I have spent most of the day trying to figure this out, I know that the problem is that the TextBlock thinks that it has infinite width, so the wrapping never occurs, I have tried a lot of bindings to set the width of the grid, ContentPane, etc; without any luck; this user control is hosted withing a ig:Dock of a larger application that can be dynamically re-sized, so I can't just set a width to the text, I believe I need some sort of binding... any help would be appreciated.</p>
  
  <pre><code>&lt;UserControl x:Class="VistaSTAR_Client.Views.XMLEditor"
          xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
          xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
          xmlns:igDock="http://infragistics.com/DockManager"
          xmlns:ig="http://schemas.infragistics.com/xaml"
          mc:Ignorable="d" 
          xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
          xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"&gt;
  
      &lt;UserControl.Resources&gt;
          &lt;SolidColorBrush x:Key="xmlValueBrush" Color="Blue" /&gt;
          &lt;SolidColorBrush x:Key="xmAttributeBrush" Color="Red" /&gt;
          &lt;SolidColorBrush x:Key="xmlTagBrush" Color="DarkMagenta" /&gt;
          &lt;SolidColorBrush x:Key="xmlMarkBrush" Color="Blue" /&gt;
          &lt;DataTemplate x:Key="attributeTemplate"&gt;
              &lt;StackPanel Orientation="Horizontal" Margin="3,0,0,0" HorizontalAlignment="Center"&gt;
                  &lt;TextBlock Text="{Binding Path=Name}" Foreground="{StaticResource xmAttributeBrush}"/&gt;
                  &lt;TextBlock Text="=&amp;quot;" Foreground="{StaticResource xmlMarkBrush}"/&gt;
                  &lt;TextBlock Text="{Binding Path=Value}" Foreground="{StaticResource xmlValueBrush}"/&gt;
                  &lt;TextBlock Text="&amp;quot;" Foreground="{StaticResource xmlMarkBrush}"/&gt;
              &lt;/StackPanel&gt;
          &lt;/DataTemplate&gt;
  
          &lt;HierarchicalDataTemplate x:Key="NodeTemplate"&gt;
              &lt;StackPanel Orientation="Horizontal" Focusable="False"&gt;
                  &lt;TextBlock x:Name="tbName" Text="?" /&gt;
                  &lt;ItemsControl ItemTemplate="{StaticResource attributeTemplate}" ItemsSource="{Binding Path=Attributes}" HorizontalAlignment="Center"&gt;
                      &lt;ItemsControl.ItemsPanel&gt;
                          &lt;ItemsPanelTemplate&gt;
                              &lt;StackPanel Orientation="Horizontal"/&gt;
                          &lt;/ItemsPanelTemplate&gt;
                      &lt;/ItemsControl.ItemsPanel&gt;
                  &lt;/ItemsControl&gt;
              &lt;/StackPanel&gt;
              &lt;HierarchicalDataTemplate.ItemsSource&gt;
                  &lt;Binding XPath="child::node()" /&gt;
              &lt;/HierarchicalDataTemplate.ItemsSource&gt;
              &lt;HierarchicalDataTemplate.Triggers&gt;
                  &lt;DataTrigger Binding="{Binding Path=NodeType}" Value="Text"&gt;
                      &lt;Setter TargetName="tbName" Property="Text" Value="{Binding Path=Value}"/&gt;
                  &lt;/DataTrigger&gt;
                  &lt;DataTrigger Binding="{Binding Path=NodeType}" Value="Element"&gt;
                      &lt;Setter TargetName="tbName" Property="Text" Value="{Binding Path=Name}"/&gt;
                  &lt;/DataTrigger&gt;
              &lt;/HierarchicalDataTemplate.Triggers&gt;
          &lt;/HierarchicalDataTemplate&gt;
          &lt;XmlDataProvider x:Key="xmlDataProvider"&gt;
          &lt;/XmlDataProvider&gt;
      &lt;/UserControl.Resources&gt;
  
  
  
      &lt;Grid&gt;
          &lt;Grid.RowDefinitions&gt;
              &lt;RowDefinition Height="*" /&gt;
          &lt;/Grid.RowDefinitions&gt;
          &lt;Grid.ColumnDefinitions&gt;
              &lt;ColumnDefinition Width="*" /&gt;
          &lt;/Grid.ColumnDefinitions&gt;
          &lt;igDock:XamDockManager Name="XMLDockManager" Theme="IGTheme" LayoutMode="FillContainer"&gt;
              &lt;igDock:XamDockManager.Panes&gt;
                  &lt;igDock:SplitPane Width="Auto" HorizontalAlignment="Stretch"&gt;
                      &lt;igDock:TabGroupPane Width="Auto" HorizontalAlignment="Stretch"&gt;
                      &lt;igDock:ContentPane Name="XMLTreeView" Header="Tree View" Width="Auto" HorizontalAlignment="Stretch"&gt;
                          &lt;TreeView Name="treeView1" Background="AliceBlue" HorizontalAlignment="Stretch" Height="Auto" Width="Auto" Margin="5,5,5,5"
                              ItemsSource="{Binding Source={StaticResource xmlDataProvider}, XPath=*}" ItemTemplate= "{StaticResource NodeTemplate}"/&gt;
                      &lt;/igDock:ContentPane&gt;
                      &lt;igDock:ContentPane Name="XML" Header="Editor"&gt;
                          &lt;TextBox HorizontalAlignment="Stretch" Name="text" Text=" " TextWrapping="WrapWithOverflow" Height="Auto" Width="Auto"
                              VerticalScrollBarVisibility="Auto" VerticalAlignment="Stretch" AcceptsReturn="True" AcceptsTab="True" Margin="5,5,5,5" Grid.Row="1" /&gt;
                      &lt;/igDock:ContentPane&gt;
                      &lt;/igDock:TabGroupPane&gt;
                  &lt;/igDock:SplitPane&gt;
              &lt;/igDock:XamDockManager.Panes&gt;
          &lt;/igDock:XamDockManager&gt;
  
      &lt;/Grid&gt;
  &lt;/UserControl&gt;
  </code></pre>