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 | | 42 Comments

42 Comments »

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

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

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

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

  3. nice work

    Comment by sacha | February 6, 2008 | Reply

  4. thanks :)

    Comment by marlongrech | February 6, 2008 | Reply

  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 | Reply

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

    Thanks for the control :)

    Comment by Chaks | February 7, 2008 | Reply

  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 | Reply

  8. Thanks Chaks….

    Comment by marlongrech | February 7, 2008 | Reply

  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 | Reply

  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 | Reply

  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 | Reply

  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 | Reply

  13. Are you using .net 3.5?

    Comment by marlongrech | February 19, 2008 | Reply

  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 | Reply

  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 | Reply

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

    Comment by marlongrech | February 21, 2008 | Reply

  17. 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 | Reply

  18. 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 | Reply

  19. 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 | Reply

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

    Comment by marlongrech | April 4, 2008 | Reply

  21. 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 | Reply

  22. 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 | Reply

  23. (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 | Reply

  24. 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 | Reply

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

    Comment by marlongrech | May 18, 2008 | Reply

  26. 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 | Reply

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

    Comment by Zubair Noman | May 20, 2008 | Reply

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

    Comment by ruchi | May 21, 2008 | Reply

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

    Comment by marlongrech | May 21, 2008 | Reply

  30. 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 | Reply

  31. 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 | Reply

  32. Hi!

    Nice work. Any plans to do support for multi-month display (show 2 or more months at the same time)? We are searching for a datetime control that has support for that.

    Comment by Alexander | August 17, 2008 | Reply

  33. Hi there,

    Right now the DatePicker does not support, showing multiple months at the same time yet it can be refactored to do so quite easily…. If you need any help doing this email me and I will help :D

    Regards

    Comment by marlongrech | August 17, 2008 | Reply

  34. hi, i am new to wpf and i was looking for a datepicker. i tried to use yours but when i choose month November give’s error and in the list box with the months it’s shows ‘Novemeber’ and say’s cannot find the month

    i am using vs 2008
    any ideas?

    regards from Athens, Greece

    Comment by anna | October 2, 2008 | Reply

  35. The missing november (showing up any day now) was a sinple typy in DateHelper.cs change: Novemeber -> November.

    Multi-month is a nice feature. Ususally see this not wep pages.

    Would also be nice to have internationalization support.
    Could add a simple interface for Date/Month names we can replace with own code (We use custom internationalization, not standard WPF).
    Ditlef

    Comment by Ditlef | October 23, 2008 | Reply

  36. This is extremely visually appealing. The only thing I would really suggest is to maybe include an OK and CANCEL. The reason for that is if you first change the date, then the picker collapses after date selection and you have to reinstitute the picker to change the time. There were other things I noticed that led me to think this functionality would be nice (ie: click on the GUI clock and the picker collapses), but like I said very nicely done.

    Comment by brcpar | November 7, 2008 | Reply

  37. You Will Love mine, Check it Now

    Comment by adding comment in picture | November 29, 2008 | Reply

  38. I like this wishes

    Comment by chinese new year firework | November 30, 2008 | Reply

  39. Hi,

    After choosing month->day the control don’t want to roll-back, and I have to click on it to close editing (choosing) mode. Any idea hov to close this feature after clicking a day?

    Best regards

    Comment by alias | April 3, 2009 | Reply

  40. hi,

    The control looks good but I can’t get it to work in my application. (works fine in the demo)
    It doesn’t display the date-time selected at all, both in the header form and expanded. Controls seem to work exept that no information appears to be stored.

    Any ideas?

    I’m new to WPF so it is likely to be something stupid and simple…

    Thanks in advance

    Comment by Chris | April 21, 2009 | Reply

  41. Hi,

    Great effort here to produce a viable datetime picker. It’s ridiculous that it has not yet been produced by the WPF team, but that’s just me being picky.

    I have one question though: how do I make the control editable? I mean, the textbox of the combobox that stays visible, how do i make it editable?

    Thank you

    Comment by Manuel Pimenta | June 1, 2009 | Reply


Leave a comment