DataGridTextColumn binding problem

Jan 9, 2009 at 4:57 PM
Edited Jan 9, 2009 at 11:39 PM
Hi all,

I have bound data to DataGrid columns, and in doing so, changed the column header names to be more readable.  My problem is that at a later point in time, I need the original column name.  How do I go about getting the binding information?  

For example, my column definition is as follows:

<dg:DataGridTextColumn Header="Created On" Width="135" Binding="{Binding WhenCreated}" IsReadOnly="True"/>

In this case, the table column is bound to the field "WhenCreated" but the header is set to display "Created On".  At some point in my C# code, I get a handle on the DataGridTextColumn .  Its Header returns "Created On", and I have no idea how to get back to the "WhenCreated" value.  In the debugger, I can see that the "WhenCreated" value is way down in the  DataGridColumn.Binding.Path, but I can't seem to get to it.   Using BindingOperations.GetBinding on the DataGridColumn.Header returns null.  But I'm not really binding to the header.  So how do I get the binding information on a DataGridColumn?

Thanks in advance for your help.

Below is more of the XAML in question:

        <dg:DataGrid HorizontalAlignment="Stretch" VerticalAlignment="Stretch"  
                        DockPanel.Dock="Top" Height="Auto" Width="Auto" Name="Plates" IsReadOnly="True"  
                        SelectionChanged="Plates_SelectionChanged" Loaded="Plates_Loaded" 
                        CanUserAddRows="False" Margin="5,5,5,5"  
                <dg:DataGridTextColumn Header="Created On" Width="135" Binding="{Binding WhenCreated}" IsReadOnly="True"/> 
                <dg:DataGridTextColumn Header="Created By" Width="75" Binding="{Binding CreatedBy}" IsReadOnly="True"/> 
                <dg:DataGridTextColumn Header="Modified On" Width="135" Binding="{Binding WhenModified}" IsReadOnly="True"/> 
                <dg:DataGridTextColumn Header="Modified By" Width="75" Binding="{Binding ModifiedBy}" IsReadOnly="True"/> 
Jan 13, 2009 at 2:52 AM
So it looks like what you want is the binding that the column is set to.  You will have to go through a DataGridCell of the column.  So for the first column, say cell 1, you will need to get the UIElement of the cell, TextBlock.  With that you can use the BindingOperations.GetBinding.
Jan 14, 2009 at 4:59 PM
Thanks very much!