This project has moved. For the latest updates, please go here.

TimePicker - show current time on startup

Jul 21, 2011 at 7:07 PM

When a TimePicker is instantiated it is initially displayed with an empty input box. However, it appears that the control has been initialized with the current time i.e. if one of the spinner arrows is clicked the current time appears in the input box. How can I get the control to display the time, as opposed to an empty box, without having to interact with one of the spinners or the interval drop-down first?


Jul 21, 2011 at 7:24 PM

The TimePicker DefaultValue is meant for data binding scenarios.  As a workaround you could handle the Loaded event of the control and simply set the Value to appropriate DateTime.  Or you can databind a property to the Value and set the default value of the Property accordingly.

Jul 21, 2011 at 7:46 PM

Thanks so much Brian! I'm not far enough up the WPF learning curve to help myself when the documentation gets scarce, so your help is much appreciated...

Jul 21, 2011 at 7:48 PM

Are you using data binding?

Jul 22, 2011 at 1:16 PM

No, I'm not. I'm in the process of mocking-up a user interface to replace an existing product. At this point none of the back-end design work has been done.

Jul 22, 2011 at 3:16 PM

One way is to handle the loaded event of the Window or control.  In the event handler set timePickerInstance.Value = DateTime.Now.