16

According to this post, there's a separate DatePicker control in .net 4. I've tried it, and I don't see a good way to also let it select the time of the day.

Is there an easy way to transform DatePicker into DateTimePicker by editing XAML template? If not, what is the best way to get a DateTimePicker for WPF 4.0?

Community
  • 1
  • 1
Arsen Zahray
  • 24,367
  • 48
  • 131
  • 224

4 Answers4

34

Extended WPF Toolkit sports a nice DateTimePicker with time of day.

There is also an article over on CP where someone created a control that works like the Winforms one... A WPF DateTimePicker That Works Like the One in Winforms

John Cummings
  • 1,949
  • 3
  • 22
  • 38
Dean Kuga
  • 11,878
  • 8
  • 54
  • 108
  • 1
    That nice `DateTimePicker` keeps disappearing out of the namespace it's declared under in the XAML. – ProfK Oct 08 '14 at 18:04
10

There isn't one without making it yourself or using a 3rd party control. However there is one within winforms if you want a quick fix that doesn't support data binding...

xmlns:window="clr-namespace:System.Windows.Forms.Integration;assembly=WindowsFormsIntegration"
xmlns:wf="clr-namespace:System.Windows.Forms;assembly=System.Windows.Forms"

<window:WindowsFormsHost >
    <wf:DateTimePicker Format="Time" ></wf:DateTimePicker>
</window:WindowsFormsHost>

Just a time picker, but could easily be paired with a datepicker. You also need a reference to WindowsFormsIntegration and System.Windows.Forms.

Kevin DiTraglia
  • 25,746
  • 19
  • 92
  • 138
7

Try the DateTimePicker in the extended WPF toolkit.

Phil
  • 42,255
  • 9
  • 100
  • 100
6

If you do want an DateTimePicker without external controls and also for commercial use, I've improved an existing one and share it here: https://gist.github.com/Apflkuacha/406e755c8b42a70b7ab138e6b985bcdf

It will look like this, a field which shows the selected date&time and a popup window to select the date and time:

DateTimePicker

Coden
  • 2,579
  • 1
  • 18
  • 25
  • I keep getting "The resource InvertBoolConverter cannot be resolved". How do I make it find it? – Eric Bourque Feb 21 '22 at 16:24
  • I do have it in my shared resources, but I do have updated the gist to make clear how to define it. The converter itself is included in the code-behind file in the gist. – Coden Feb 22 '22 at 15:54