Bind Datepicker

Nov 17, 2008 at 3:25 PM
I have following code:

 

 

<dg:DataGridTemplateColumn Header="Expense Date" MinWidth="100">

   <dg:DataGridTemplateColumn.CellEditingTemplate
>
        <DataTemplate
>
            <dg:DatePicker Name="dtExpenseDate" SelectedDate="{Binding Path=ExpenseDate}" SelectedDateFormat
="Short" />
        </DataTemplate
>
    </dg:DataGridTemplateColumn.CellEditingTemplate>

 

 

 

    <dg:DataGridTemplateColumn.CellTemplate >
        <DataTemplate
>
            <TextBlock Text="{Binding ExpenseDate
}"/>
        </DataTemplate
>
    </dg:DataGridTemplateColumn.CellTemplate
>

</dg:DataGridTemplateColumn
>
----- End Of Code

The data is displayed using a datatable. It displays the date from the datatable. But, when I change the date using the datepicker. It does not retian the selected date.

How do I bind the CellTemplate to display the date selected using datepicker?

Thanks

Coordinator
Nov 19, 2008 at 7:23 PM
Edited Nov 19, 2008 at 7:29 PM
Thanks for finding this issue, J12 :-)  The following workaround should help you out:

<dg:DataGridTemplateColumn Header="Expense Date">

    <dg:DataGridTemplateColumn.CellEditingTemplate>

        <DataTemplate>

            <dg:DatePicker Name="dtExpenseDate" 
                           SelectedDate
="{Binding Path=ExpenseDate, Mode=TwoWay}" />     
        </DataTemplate>

    </dg:DataGridTemplateColumn.CellEditingTemplate>



    <
dg:DataGridTemplateColumn.CellTemplate >

        <DataTemplate >

            <TextBlock Text="{Binding ExpenseDate}"/>

        </DataTemplate>

    </dg:DataGridTemplateColumn.CellTemplate >

</dg:DataGridTemplateColumn>


The difference here is the explicit use of TwoWay Binding with SelectedDate.


-Eric Fabricant, MSFT
Nov 20, 2008 at 2:08 PM
Thanks Eric,

Should have thought myself :).