Reset WPF Tookkit datepicker parameter value to default value

When I first open my window, which uses the wpf toolkit date, it has today's date highlighted in the calendar, but nothing in the corresponding text box (expect the water sign in mm / dd / yyyy).

I want to reset the datepick to this initial state after the user selects the date and "sends", so when they use it again, it is not on the date they previously selected. For example, if a person selects a date after 2 months, when it is reset, the text box is the watermark mm / dd / yyyy, and when the calendar opens, it starts from today as β€œstart date”.

I tried various combinations of the following, but this does not 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 only text, the calendar (selected date \ start) will not reset. But if I set the calendar, the text is updated, not just the watermark.

Any ideas?

thanks

+4
source share
1 answer

I believe that you are looking for the DisplayDate property. This property, which is not NULL, corresponds to the date selected in the calendar control. I tested the following in a quick one-time WPF application and it worked fine. Commenting out the line in which DisplayDate is installed describes the behavior you are describing.

 datePicker1.SelectedDate = null; datePicker1.DisplayDate = DateTime.Today; 
+5
source

Source: https://habr.com/ru/post/1313464/


All Articles