title: How to get Binding name from DataTemplate
body: <p>I'm trying to sort a ListView by it's headers. </p>
  
  <p>I'm following this <a href="https://docs.microsoft.com/en-us/dotnet/framework/wpf/controls/how-to-sort-a-gridview-column-when-a-header-is-clicked" rel="nofollow noreferrer">MSDN example</a>, with the alternation given <a href="https://stackoverflow.com/a/13050504/6296435">here</a> - where this line works if I were to use direct binding:</p>
  
  <pre><code>GridViewColumnHeader headerClicked = e.OriginalSource as GridViewColumnHeader;
  string sortString = ((Binding)headerClicked.Column.DisplayMemberBinding).Path.Path
  </code></pre>
  
  <p>But problem is I'm not binding the columns directly using <code>DisplayMemberBinding="{Binding PVNum}"</code> but rather I am using CellTemplate: </p>
  
  <pre><code>&lt;ListView.Resources&gt;
      &lt;DataTemplate x:Key="NumberTemplate"&gt;
          &lt;TextBlock Text="{Binding PVNum}" TextAlignment="Center"  /&gt;
      &lt;/DataTemplate&gt;
  &lt;/ListView.Resources&gt;
  
  &lt;ListView.View&gt;
    &lt;GridView AllowsColumnReorder="False"&gt;
       &lt;GridView.Columns&gt;
          &lt;GridViewColumn Header=" " CellTemplate="{StaticResource NumberTemplate}"/&gt;
        &lt;/GridView.Columns&gt;
     &lt;/GridView&gt;
  &lt;/ListView.View&gt;
  </code></pre>
  
  <p>So my question is - how do I get this "PVNum" string in the code behind? </p>
  
  <p>I did try this, though s is null - so I guess I'm off:</p>
  
  <pre><code> var t = headerClicked.Column.CellTemplate.LoadContent() as TextBlock;
   var s = t.GetBindingExpression(TextBox.TextProperty);
  </code></pre>
  
  <p>Any suggestions?</p>