title: Binding an event to a control created with a data template in WPF
body: <p>in my WPF project I create a custom ListView in Code Behind. In this ListView is a column that contains a button, defined by a datatemplate in my resource dictionary.</p>
  
  <pre><code>&lt;DataTemplate x:Key="DataTemplate_EditButton"&gt;
    &lt;Button Style="{DynamicResource Button_Image}" Width="25" ... /&gt;
  &lt;/DataTemplate&gt;
  </code></pre>
  
  <p>When I initialize the ListView, I create the column with the following code:</p>
  
  <pre><code>GridViewColumn buttonColumn = new GridViewColumn();
  DataTemplate dt = Application.Current.TryFindResource("DataTemplate_EditButton") as DataTemplate;
  buttonColumn.CellTemplate = dt;
  ...
  
  gridView.Columns.Add(buttonColumn);
  </code></pre>
  
  <p>Now I want to bind an event handler to the click event of the button. I cannot do it in the template, because I would need to create a code behind class for the Dictionary and I need the event handler in the ListView-UserControl anyway. When I create the column with the data template there is of course no way to access the button that is created for each row.</p>
  
  <p>What would be the best way to deal with the click event of the buttons created in the described way?</p>
  
  <p>Thanks in advance,<br>
  Frank </p>