Take the 2-minute tour ×

This is a possible duplicate of Set the Default Date of WPF Date Picker to Current Date but I have tried the code from the question and it doesn't work, hopefully I am missing something simple

OK as the question states, I want to display the current date when the view loads, however, I have the SelectedDate property bounded to a property of mine, and I dont think you can use "Text" because the property that I am binding to is a DateTime property. yes, I could do a convert in the model but XAML (I think) should be able to do this for me.

OK I know what is the problem, the date is coming out "01/01/0001" because of course, its binding to my property which is defaulted to 01/01/0001, so I guess I will need to do some C# code in my property to say if its 01/01/0001, use DateTime.Now and if not, use the property.


    <DatePicker HorizontalAlignment="Left" 
                DisplayDate="{x:Static System:DateTime.Now}"
                SelectedDate="{Binding AvailableFrom, Mode=TwoWay}"

Am happy to delete this after if the big reps think it is a duplicate,

What I did to resolve...


         if (m_AvailableFrom == DateTime.MinValue)
             return DateTime.Now;

        return m_AvailableFrom;

Cheers for the help

share|improve this question
Answers, even from the OP, go in the answers section. Please remove the answer from the question then post it as an answer. –  Josh Graham May 2 at 16:59

2 Answers 2

up vote 0 down vote accepted

I personally would just assign DateTime.Now to the AvailableFrom property in the ViewModel code.

If you want to use XAML though, one option is to make the AvailableFrom property a DateTime? (nullable DateTime) rather than a DateTime. Then the default value is null rather than "01/01/0001".

Then, in your XAML you can use


        TargetNullValue={x:Static System:DateTime.Now}}"
    Width="120" />

and the UI will display the current date anytime that AvailableFrom is null.

share|improve this answer
Hi Josh, this is what I have done, but in the Model, I will past code above, cheers –  user3428422 May 2 at 15:45
<DatePicker HorizontalAlignment="Left"                 
        SelectedDate="{Binding AvailableFrom, Mode=TwoWay}"
        DisplayDate="{Binding DateTime.Now}"                

*Use DisplayDate after SelectedDate

mark if this useful thanks!

share|improve this answer

Your Answer


