WPF DatePicker default to today's date

developer picture developer · Oct 7, 2010 · Viewed 88.9k times · Source

WPF DatePicker always show 'Show Calendar' by default. I want it to show current/todays date. How do I do that. I tried doing something like the below in the constructor but it won't work,

datePicker.SelectedDate = DateTime.Now.Date;

or

datePicker.DisplayDate = DateTime.Now.Date;

Answer

Kishore Kumar picture Kishore Kumar · Oct 8, 2010

please try with this ....

<my:DatePicker SelectedDate="{x:Static sys:DateTime.Now}"/>

add this reference

xmlns:sys="clr-namespace:System;assembly=mscorlib"