C# Disciples

my life in Avalon ….

WPF Date Time Picker

[updated 09th Febuary 2008 - Bug fix for DateTimePicker]
After loads of requests for a DateTimePicker in AvalonControlLibrary I finally had sometime to build a DateTimePicker. DateTimePicker is nothing really special it is a DatePicker and a TimePicker combined in one control.

DateTimePicker exposes an important property called DateTimeSelected. DateTimeSelected is a dependency property so that you can use it in data binding. DateTimePicker also exposes an event DateTimeSelectedChanged that is raised whenever the date/time is changed.

There are some other useful properties that you can set to layout this control

MinuteHand - This property takes a Brush and it is used to color the minute hand

HourHand - This property takes a Brush and it is used to color the hour hand

ClockBackground - This property takes a Brush and it is used as Background color for the clock

CalanderHeaderBackground - This property takes a Brush and it is used as Background for the header of the calander

CalanderHeaderForeground - This property takes a Brush and it is used as Foreground for the header text of the calander

This control also supports control templates. You MUST supply a DatePicker named PART_DatePicker and a TimePicker named as PART_TimePicker in order to create a ControlTemplate for this control.

This control will ship in v2 of AvalonControlLibrary. If you have any suggestions or find any bugs please let me know so that I can update it before I release AvalonControlLibrary v2.

Download Demo Project Here

Please note that a new version is available here

DateTimePicker

kick it on DotNetKicks.com

February 6, 2008 - Posted by marlongrech | .Net 3.0, .Net 3.5, WPF, WPF Custom Controls | | 32 Comments

32 Comments »

  1. [...] See also DatePicker See alse DateTimePicker [...]

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

  2. [...] See alse DateTimePicker [...]

    Pingback by WPF DatePicker « C# Disciples | February 6, 2008

  3. nice work

    Comment by sacha | February 6, 2008

  4. thanks :)

    Comment by marlongrech | February 6, 2008

  5. This is looking great, Marlon. Thank you!

    I’m wondering if this control supports European weeks starting at Monday, which I’ll probably find out after downloading :).

    For business applications it would also be a great option to display the week number to the left of each week using a specific CultureInfo, CalendarWeekRule and FirstDayOfWeek:

    int weekno = specifiedCultureInfo.Calendar.GetWeekOfYear(dateInWeek, CalendarWeekRule.FirstFourDayWeek, DayOfWeek.Monday)

    Comment by horst | February 7, 2008

  6. Cool..will test this in the weekend :)

    Thanks for the control :)

    Comment by Chaks | February 7, 2008

  7. Hi horst,

    Thanks for the suggestion. I will have a look at it and update this for AvalonControlsLibrary v2

    Thanks again :D

    |Regards

    Comment by marlongrech | February 7, 2008

  8. Thanks Chaks….

    Comment by marlongrech | February 7, 2008

  9. Hello again, Marlon.

    Just in case you consider adding support week numbers:

    I just discovered that FirstFourDayWeekRule
    and the GetWeekOfYear method is broken and does not produce
    week numbers according to ISO 8601.

    Maybe a function to produce the correct week numbers could be passed to the control.

    Comment by horst | February 7, 2008

  10. Hi there,

    Thanks for this… I will look into it. if you have any more ideas that you would like to share I would suggest that you send me an email on marlongrech@gmail.com

    Thanks a lot and a lot :D

    Comment by marlongrech | February 7, 2008

  11. Hello everyone,

    While refactoring code for DateTimePicker and making Routed events for time picker and datepicker, I found a major bug in the DateTimePicker control. The bug is basically when you set the date time manually the time is not set correctly! Thanks to the unit tests this was detected while I was refactoing the control and now it should be fixed. I uploaded the new version of the control. Sorry for any inconvience.

    Regards

    Comment by marlongrech | February 9, 2008

  12. I can’t seem to get this to work in an XBAP application (the control doesn’t appear at all). Do you know of any way to get this to work in an XBAP or is it not possible b/c of the sandbox… thanks -

    Comment by Kelly Todd | February 19, 2008

  13. Are you using .net 3.5?

    Comment by marlongrech | February 19, 2008

  14. yes, i tried building it in both 05 and 08 and i’m running 3.5 framework. I’m also building it as a ‘full trust application’ according to the property settings. The page loads fine with no errors - just the control is invisible/blank (i can still see the text box controls though). I’ve seen this with other controls also - could it be because the control has ‘popup’ markups? i’ve read something about this in other forums… Thanks for the help

    Comment by Kelly Todd | February 20, 2008

  15. figured out the issue - i was trying to create a UserControl from your project and my project name was different from yours. In your Generic.xaml you had the project name listed in your code:

    just changed the ‘DateTimePickerDemo’ to my project name and everything is good now.

    Thanks for the great component!

    Comment by Kelly Todd | February 20, 2008

  16. Great job Kelly… 5 stars for u :D

    Comment by marlongrech | February 21, 2008

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

    Comment by marlongrech | March 3, 2008

  18. I use this control and it works fine for english culture. Please can u tell me how can I make it work for other cultures like de-DE at run time? Thanks

    Comment by Nilesh Makwana | March 20, 2008

  19. Is it posible to navigate through the control just with keyboard? To spring from month’s field to year’s to day’s … It should be used on a tv with a remote control.

    Is there any method to get the popUp open when the control
    gets the keyboard focus?

    Thanks!

    Comment by Gomez | March 27, 2008

  20. Hi,
    can you post some code for databinding?
    It seems not to work in my solution…

    My code looks like this:

    Comment by Myself | April 3, 2008

  21. if you download the source code there are examples of how to databindind to the TimePicker

    Comment by marlongrech | April 4, 2008

  22. Hi,

    i just found how to bind to a textbox…
    I wanted to bind it to da row of a dataset where the datetime may be null…

    If this is not possible i need to know how to display no date… Can you tell me how i can do this?

    Comment by Myself | April 7, 2008

  23. Hi there,

    There is no feature in the current version of the date picker to display no date…. I would suggest that you disable the datepicker control when the date is null… You can do this via a trigger or converter…. If you want send me an email and I can send you a sample or something…

    Regards

    Comment by Marlon Grech | April 7, 2008

  24. (1) i want to manualy enter date instead of selecting with mouse, how is it possible?
    (2) how can i change the background on keyboard focus?

    Comment by Nilesh Makwana | April 23, 2008

  25. I want to highlight current date and time when
    date time control first time drop down.
    Once we select date, then it highlights that date
    when it is drop down but i want to highlight current
    date when it is first time drop down.

    Please help me if you have any ideas

    Thank You
    Sanjay L. Dholakiya

    Comment by Sanjya L. Dholakiya | May 18, 2008

  26. I did not understand what you mean can you please repeat

    Comment by marlongrech | May 18, 2008

  27. Hi,

    I want the combobox textbox editable so that the user can edit the date directly without opening the combobox, how can this be done.

    Comment by WPF Learner | May 20, 2008

  28. Hi Marlon Grech, this is a lovely control, I needed this .. thanks for the help.

    Comment by Zubair Noman | May 20, 2008

  29. link is not opening .. :( anyone can send me the code???

    Comment by ruchi | May 21, 2008

  30. I just updated the link. Can you please try again.

    Comment by marlongrech | May 21, 2008

  31. Hi, nice control
    I just expected the time to be editable by dragging the niddles on the watch too :p
    That would be a cool feature to use with a stylus, as I’m developping apps for TabletPC!
    Also, The dropdown with the month has an error, the November is spelled Novemeber, and that throws an exception when you choose it directly.
    Regards,

    Stéphane

    Comment by Stephane | June 9, 2008

  32. Just a newbie learning, SHOCKED at the ease I was able to use Avalon Controls(DateTimePicker)Clicked on Designer inVS2008 Express , hit General area in toolbox “Choose Items…”, browsed to Avalon ,still on desktop & away we Go ! Dayum !
    THANKZ Pal, NOT one word of code just dragged onto the form,
    ( Like I said, a newbie !) Thankz again, been Googleing for hours for help !
    BLESS YOU !!!!!

    Comment by SteveH | June 14, 2008

Leave a comment