views:

30

answers:

1

When I first open my window that uses the wpf toolkit datepicker it has today's date highlighted in the calendar but nothing in the associated textbox (expect a water mark of mm/dd/yyy).

I want to reset the datepick to that initial state after a user selects a date and "submits" so when they use it again it not at the date they previously selected. So for example if a person selected a date 2 months from now, when it is reset the text box is the mm/dd/yyyy watermark and when the calendar is opened it starts with today's date as the 'starting date'.

I've tried various combinations of the following but this doesn't reset the text:

//set date to today so it move the calendar to this date
mydatepicker.SelectedDate = DateTime.Now;
//reset since we don't want a date selected
mydatepicker.SelectedDate = null;
//reset the text
mydatepicker.Text = string.Empty;

If i reset just the text the calendar (selected date\starting) is not reset. But if i set the calendar the text is updated and not long just the watermark.

Any ideas?

Thanks

+1  A: 

I believe what you're looking for is the DisplayDate property. This property, which is not nullable, corresponds to the date currently selected in the calendar control. I tested the following in a quick one-off WPF app and it worked fine. Commenting out the line that set DisplayDate gave the behavior you describe.

datePicker1.SelectedDate = null;
datePicker1.DisplayDate = DateTime.Today;
Josh Einstein