Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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 ?

like image 676
Ananth Avatar asked Dec 08 '25 06:12

Ananth


1 Answers

(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)

like image 162
paul Avatar answered Dec 10 '25 20:12

paul



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!