I am trying to get the name of the property associated with a particular DataGridColumn
, so that I can then do some stuff based on that. This function is called when the user clicks context menu item on the column's header...
This is fine for the out-of-the-box ready-rolled column types like DataGridTextColumn
, since they are bound, but the problem is that some of my columns are DataGridTemplateColumns
, which are not bound.
private void GroupByField_Click (object sender, RoutedEventArgs e){
MenuItem mi = (MenuItem)sender;
ContextMenu cm = (ContextMenu) mi.Parent;
DataGridColumnHeader dgch = (DataGridColumnHeader) cm.PlacementTarget;
DataGridBoundColumn dgbc = (DataGridBoundColumn) dgch.Column;
Binding binding = (Binding) dgbc.Binding;
string BoundPropName = binding.Path.Path;
//Do stuff based on bound property name here...
}
So, take for example my Name
column... it's a DataGridTemplateColumn
(since it has an image and some other stuff in there). Therefore, it is not actually bound to the 'Name' property... but I would like to be, so that the above code will work.
My question is two-part, really:
Is it possible to make a
DataGridTemplateColumn
be BOUND, so that the above code would work? Can I bind it somehow to a property?Or do I need to something entirely different, and change the code above?
Thanks in advance!
AT