Monday, December 3, 2012

Set the Default Date of SilverLight Date Picker to Current Date

Set the Default Date of SilverLight Date Picker to Current Date

I have a SilverLight Datagrid in which one of the columns is a Date Column.

So i have used a DataTemplateColumn as Follows

 <sdk:DataGridTemplateColumn   Header="Recieved Date" Width="Auto">                         <sdk:DataGridTemplateColumn.CellTemplate>                             <DataTemplate>                                 <TextBlock Text="{Binding Path=RecievedDate, StringFormat='MM/dd/yyyy'}" />                             </DataTemplate>                         </sdk:DataGridTemplateColumn.CellTemplate>                         <sdk:DataGridTemplateColumn.CellEditingTemplate>                             <DataTemplate>                                 <sdk:DatePicker Name="dtpFinancialAndComplianceLog" Text="{Binding Path=RecievedDate, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" />                             </DataTemplate>                         </sdk:DataGridTemplateColumn.CellEditingTemplate>                     </sdk:DataGridTemplateColumn> 

The problem is when i click on the DatePicker control the default date is set to 1/1/0001?

How can i set my datepicker to set to the current Date in Edit mode ?

I tried DisplayDateStart="{x:Static sys:DateTime.Now}" . But thats not working as Static only works works with WPF and doesnt work with Silverlight .

What would be the best way to set my datepicker to set to the current Date upon editing ?

Answers & Comments...

Answer: 1

(from comments above to OP)

If you omit DisplayDate doesn't the Silverlight datepicker default to today's date?

Also, if you always want to start with todays date, you could try updating the direction of your binding to OneWay (i.e. no need for any binding code to try to set what starts off in the box)

by : paulhttp://stackoverflow.com/users/1280587




No comments:

Post a Comment

Send us your comment related to the topic mentioned on the blog