title: Where is WPF setting GridViewRowPresenter.Columns for GridView
body: <p>I'm recently exploring a <a href="http://msdn.microsoft.com/en-us/library/vstudio/ms771523%28v=vs.90%29.aspx" rel="nofollow">sample</a> of using the <code>GridViewRowPresenter</code> inside a <code>TreeView</code> to make it like a "treegrid". To do this one generally need to define a <code>GridViewColumnCollection</code>, and set it to <code>GridViewRowPresenter.Columns</code> explicitly. The sample works for me very well. </p>
  
  <p>However since <code>GridViewRowPresenter</code> is most often used with <code>ListView</code> and <code>GridView</code>. I begin to wonder how does the <code>ListView</code> and <code>GridView</code> setting the Columns property for each row. The xaml most likely like this:</p>
  
  <pre><code>&lt;ListView&gt;
      &lt;ListView.View&gt;
          &lt;GridView&gt;
              &lt;GridViewColumn Header="Length" DisplayMemberBinding="{Binding}"/&gt;
          &lt;/GridView&gt;
      &lt;/ListView.View&gt;
      &lt;ListViewItem&gt;Hello&lt;/ListViewItem&gt;
      &lt;ListViewItem&gt;World&lt;/ListViewItem&gt;
  &lt;/ListView&gt;
  </code></pre>
  
  <p>Note that though the <code>GridViewColumnCollection</code> is defined explicitly, it's not set anywhere for the <code>ListViewItem</code>. Eventually each <code>ListViewItem</code> will contain a <code>GridViewRowPresenter</code>, but in no where the Columns property is set. I checked the open source code for <code>ListView.cs</code>, <code>ListView.xaml</code>, <code>ListViewItem.cs</code>, <code>ListViewItem.xaml</code>, <code>GridViewRowPresenter.cs</code> <code>GridViewRowPresenterBase.cs</code>, in none of these the Columns property is set.</p>
  
  <p>The closest thing I found is <code>GridView.ColumnCollection</code> property, I suspect it played some role in connecting the <code>GridViewRowPresenter.Columns</code> and <code>GridView.Columns</code>, but how?</p>