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.
<DataTemplate x:Key="DataTemplate_EditButton">
<Button Style="{DynamicResource Button_Image}" Width="25" ... />
</DataTemplate>
When I initialize the ListView, I create the column with the following code:
GridViewColumn buttonColumn = new GridViewColumn();
DataTemplate dt = Application.Current.TryFindResource("DataTemplate_EditButton") as DataTemplate;
buttonColumn.CellTemplate = dt;
...
gridView.Columns.Add(buttonColumn);
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.
What would be the best way to deal with the click event of the buttons created in the described way?
Thanks in advance,
Frank