views:

315

answers:

0

This is a follow-up question to my previous one about replacing GridView contents programmatically.

I have a GridView displaying a DataSet. All of my columns are bound in my xaml with DisplayMemberBinding:

<GridViewColumn DisplayMemberBinding="{Binding Path=FirstName}" 
                        Header="First Name"
                        Width="100"/>

except for my Date of Birth column. Because I wanted to replace my DateTime.MinValue dates with blank (my previous question linked above), my date of birth column looks like:

<GridViewColumn Header="Date of Birth" Width="100">
    <GridViewColumn.CellTemplate>
     <DataTemplate>
      <TextBlock TextAlignment="Justify" 
           Text="{Binding Path=DateOfBirth, 
           Converter={StaticResource DateTimeConverter},
           ConverterParameter='MM/dd/yyyy'}" />
     </DataTemplate>
    </GridViewColumn.CellTemplate>
</GridViewColumn>

I have code that allows the user to sort the columns ascending/descending by clicking on the header. I modified the example from MSDN so that rather than using the GridViewColumn's header, it accesses the binding path to sort (the MSDN code requires your headers to match the dataset used to work, giving them "ugly" names):

string header = ((Binding)headerClicked.Column.DisplayMemberBinding).Path.Path;

This code fails, of course, when you try to sort by the Date of Birth, because there is no binding path set in DisplayMemberBinding. If I set it like the other columns, it skips my converter code.

Is it possible to access the BindingPath value set inside the TextBlock of my GridViewColumn and sort? Or does my converter coding prevent me from being able to sort on that column?