title: Data template parameter
body: <p>There is list with columns to display. I am using <code>ListView</code> with data templates for cells. And my problem is to <em>access</em> both: row and column from template.</p>
  
  <p>Below is demo, xaml:</p>
  
  <pre><code>&lt;ListView x:Name="listView" ItemsSource="{Binding Items}"&gt;
      &lt;ListView.Resources&gt;
          &lt;GridViewColumn x:Key="Column" x:Shared="False"&gt;
              &lt;GridViewColumn.CellTemplate&gt;
                  &lt;DataTemplate&gt;
                      &lt;TextBlock&gt;
                          &lt;Run Text="{Binding WhatHere}" /&gt; &lt;!-- problem here --&gt;
                          &lt;Run Text="{Binding Mode=OneWay}" /&gt;
                      &lt;/TextBlock&gt;
                  &lt;/DataTemplate&gt;
              &lt;/GridViewColumn.CellTemplate&gt;
          &lt;/GridViewColumn&gt;
      &lt;/ListView.Resources&gt;
      &lt;ListView.View&gt;
          &lt;GridView /&gt;
      &lt;/ListView.View&gt;
  &lt;/ListView&gt;
  </code></pre>
  
  <p>and the code:</p>
  
  <pre><code>public partial class MainWindow : Window
  {
      public List&lt;string&gt; Items { get; } = new List&lt;string&gt; { "1", "2", "3" };
  
      public MainWindow()
      {
          InitializeComponent();
          DataContext = this;
  
          var a = (GridViewColumn)listView.FindResource("Column");
          a.Header = "a";
          ((GridView)listView.View).Columns.Add(a);
  
          var b = (GridViewColumn)listView.FindResource("Column");
          b.Header = "b";
          ((GridView)listView.View).Columns.Add(b);
      }
  }
  </code></pre>
  
  <p>will produce</p>
  
  <p><a href="https://i.stack.imgur.com/JMnv9.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/JMnv9.png" alt=""></a></p>
  
  <p>My aim is to have:</p>
  
  <pre><code>a     b
  a1    b1
  a2    b2
  a3    b3
  </code></pre>
  
  <p>Possible? How do I <em>pass</em> column to <code>DataTemplate</code> ? In fact I want to simply know to which column current cell belongs, but please consider following:</p>
  
  <ol>
  <li>This is simplified case.</li>
  <li>In reality data templates are more complicated: many elements with bindings, triggers, etc.</li>
  <li>In reality column related data are more complicated than just header.</li>
  <li>Columns will be generated at runtime with different headers, etc.</li>
  <li>Adding columns and setting <code>Header</code> in code-behind is not a problem, <code>DataTemplate</code> is.</li>
  </ol>
  
  <p>I was thinking to use attached property on <code>GridViewColumn</code>, however, it's not parent of cells in the visual tree:</p>
  
  <p><a href="https://i.stack.imgur.com/sfm18.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/sfm18.png" alt=""></a></p>