title: Silverlight TreeViewItem width change
body: <p>I was asked to create custom TreeView based on basic TreeView from SDK. It all works, problem is: nodes/leaves do not stretch to their content, their width is always the same. Here's xaml markup:</p>
  
  <pre><code>&lt;Grid xmlns='http://schemas.microsoft.com/winfx/2006/xaml/presentation'
        xmlns:x='http://schemas.microsoft.com/winfx/2006/xaml'                                                    xmlns:sdk='http://schemas.microsoft.com/winfx/2006/xaml/presentation/sdk'&gt;
        &lt;Grid.Resources&gt;
            &lt;Style x:Key='TreeViewChildStyle' TargetType='sdk:TreeViewItem'&gt;
               &lt;Setter Property='HorizontalContentAlignment' Value='Stretch'/&gt;
               &lt;Setter Property='Background' Value='Blue'/&gt;
            &lt;/Style&gt;
        &lt;sdk:HierarchicalDataTemplate x:Key='ChildTemplate' x:Name='ChildTemplate'&gt;
               &lt;TextBlock HorizontalAlignment='Stretch' Text='{Binding Path=ChildPath}'/&gt;  
            &lt;/sdk:HierarchicalDataTemplate&gt;
        &lt;sdk:HierarchicalDataTemplate x:Key='NameTemplate' ItemsSource='{Binding Path=   ChildrenCollectionPath}' x:Name='NameTemplate' ItemTemplate='{StaticResource ChildTemplate}'&gt;
               &lt;TextBlock HorizontalAlignment='Stretch' Text='{Binding Path=ParentPath}' Width='1000'/&gt;
        &lt;/sdk:HierarchicalDataTemplate&gt;
        &lt;/Grid.Resources&gt;
        &lt;sdk:TreeView Height='Auto' Background='Red' ItemContainerStyle='{StaticResource TreeViewChildStyle}' Name='treeView1' ItemTemplate='{StaticResource NameTemplate} VerticalAlignment='Stretch' HorizontalAlignment='Stretch' BorderThickness='0'/&gt; 
  &lt;/Grid&gt;
  </code></pre>
  
  <p>I've already tried setting ItemContainer width in code behind, setting TextBlocks' width to 'Auto', setting ItemContainer width in style markup. Nothing works, TreeViewItems are always same width and it's way too narrow.</p>
  
  <p>Edit: Yes, there is SDK namespace added to grid, something just happened to editor and it's not shown, can't help it.</p>
  
  <p>Edit2: The TreeView actually changes its width to given value, yet, its Items are still not scaling.</p>