C# Disciples

my life in Avalon ….

Time Picker

While posting in the MSDN Forums of WPF, I received a lot of requests to create a TimePicker. So here it is finally, a simple yet extensible TimePicker. This control lets the user select a specific time by enter text in 3 textboxes (Hour, Minutes and Seconds). The user can also increment or decrement the time by pressing the Up and Down keys of the keyboard or even by clicking the up and down buttons that are supplied in the control. To make the user experience better when the user clicks the left or right key the focus of the textboxes changes, for example if the user is in the hours textbox and clicks the left key (if the caret index is at the end of the text) the minute text box will get focus. The Time Picker control also rounds the numbers that the user enter, for example if the user enters “88″ in the hours text box the Time Picker rounds this number to 23 (which is the highest number you can have for the hours textbox)

The Time Picker also supports ControlTemplates. There are 5 parts that you can use in your control template

->PART_Hours. This is the hours textbox you must supply this field so that the TimePicker can hook to the focus events and the text input events to change the time when text is enetered. When using this part the Time Picker will take care of adding the behaviour of focusing the next textbox when the left/right key is enetered etc..

-> PART_Minutes. This is the minutes textbox. This field is also needed for the Time Picker to change the time when text is entered. Again when using this field the time picker will hook to the events to get the behaviour mentioned above for the PART_Hours

-> PART_Seconds. This is the seconds textbox. This field is also needed for the Time Picker to change the time when text is entered. Again when using this field the time picker will hook to the events to get the behaviour mentioned above for the PART_Hours

->PART_IncreaseTime. This is a button that must be supplied to increment the time when the user click the button

->PART_Decrement. This is a button that must be supplied to decrement the time when the user click the button

Again this is a basic implementation of the TimePicker, nothing special but it is a start. I would really appreciate feedback so that I can enhance this control and maybe add some new features…

Feel free to download the code and play around with this control…

See also DatePicker
See alse DateTimePicker

Regards

TimePicker

DOWNLOAD SOURCE CODE

November 18, 2007 - Posted by marlongrech | .Net 3.0, WPF, WPF Custom Controls | | 13 Comments

13 Comments »

  1. What about a Date picker? (Time is easy…the Date picker is the one that gives me troubles implementing (properly) )

    Comment by Pop Catalin | November 19, 2007

  2. You can find a DatePicker in my blog over here
    http://marlongrech.wordpress.com/2007/09/11/wpf-datepicker/

    You can also look at the full List of controls that I have build here
    http://marlongrech.wordpress.com/avalon-controls-library/

    Comment by marlongrech | November 19, 2007

  3. How about a combination of the date and time pickers? ;)

    (I’m actually going to do this now)
    (Thanks!!!)

    Comment by Ivan | December 4, 2007

  4. That’s a great idea… If you need some help doing it let me know.. send an email at marlongrech@gmail.com

    Comment by marlongrech | December 5, 2007

  5. Hi,

    I saw your comments in my blog (http://wpfcontrols.blogspot.com/), if you are interested I could post your controls in my blog.. :)

    Let me know

    Ta,
    Rajeesh

    Comment by Rajeesh | December 6, 2007

  6. Looks nice, but why cant I get the control to work in 2005? It just wont display?

    Comment by Koos | December 10, 2007

  7. Can you please send me an email(marlongrech@gmail.com) with the source code that you are using so that I can check what is wrong… Thanks

    Comment by marlongrech | December 10, 2007

  8. [...] to build a DateTimePicker. DateTimePicker is nothing really special it is a DatePicker and a TimePicker combined in one [...]

    Pingback by WPF Date Time Picker « C# Disciples | February 6, 2008

  9. Added support for Min and Max time
    http://marlongrech.wordpress.com/2008/03/03/support-for-mindate-and-maxdate-in-datepicker-and-timepicker/

    Comment by marlongrech | March 3, 2008

  10. [...] I did a small update to the TimePicker control. I added another Property called CurrentlySelectedTime which can be used to get the current [...]

    Pingback by An update to TimePicker control in AvalonsControlLibrary « C h a k s’ C o r n e r | March 12, 2008

  11. I am not able to download TimePicker when I click on “Download Source Code” it again displays list of controls instead of download.

    Comment by suhas muchandi | May 5, 2008

  12. you can download from here
    http://www.codeplex.com/AvalonControlsLib/Release/ProjectReleases.aspx?ReleaseId=10250

    Comment by Marlon Grech | May 6, 2008

  13. How can I bind a property? I’m experiencing some problems. I bind a timespan but the timespan never gets changed =\

    How can I do it?

    Comment by AlexR | June 4, 2008

Leave a comment