I am trying to insert a textblock into the column header of a datagrid when autogeneratecolumns="true". I have the following but when I have set a beakpoint in OnColumnHeaderClick the object is null. I was hoping to get either the textblock object that was clicked or a MouseEventArgs.
public ICommand ColumnHeaderClickCommand { get; private set; } private void dataGrid1_AutoGeneratingColumn(object sender, DataGridAutoGeneratingColumnEventArgs e) { var textblock = new TextBlock(); textblock.Text = e.Column.Header.ToString(); textblock.HorizontalAlignment = HorizontalAlignment.Stretch; textblock.VerticalAlignment = VerticalAlignment.Stretch; textblock.InputBindings.Add(new MouseBinding(ColumnHeaderClickCommand, new MouseGesture() { MouseAction = MouseAction.LeftClick })); e.Column.Header = textblock; } private void OnColumnHeaderClick(object obj) { }