I wish the dropdown to show me years instead of the date of today at the start. Remark: Standard WPF DatePicker has no "DisplayMode" as shown in other sources.
3 Answers
dateTimePicker1.Format = DateTimePickerFormat.Custom;
dateTimePicker1.CustomFormat = "YYYY dd, mmmm - dddd";
OR:
dateTimePicker1.Format = DateTimePickerFormat.Custom;
dateTimePicker1.CustomFormat = "YYYY mm, dddd - dddd";
For a more expanded explanation, you can click here.
1 Comment
DJ van Wyk
The Format and CustomFormat only exists in Windows Forms. WPF has no equivalent.
Thank you very much for your answers but I found a solution which I am more content with (using just the standart control)
<DatePicker x:Name="_DatePicker" CalendarOpened="_DatePicker_CalendarOpened" />
private void _DatePicker_CalendarOpened(object sender, RoutedEventArgs e) {
// Finding the calendar that is child of stadart WPF DatePicker
DatePicker datepicker = (DatePicker)sender;
Popup popup = (Popup)datepicker.Template.FindName("PART_Popup", datepicker);
System.Windows.Controls.Calendar cal = (System.Windows.Controls.Calendar)popup.Child;
cal.DisplayMode = System.Windows.Controls.CalendarMode.Decade;
}
Good Day and Thx
Comments
If you use WPF toolkit then
<toolkit:Calendar x:Name="yearCalender" DisplayModeChanged="yearCalender_DisplayModeChanged" DisplayMode="Year" />
C# code:
private void yearCalender_DisplayModeChanged(System.Object sender, Microsoft.Windows.Controls.CalendarModeChangedEventArgs e)
{
yearCalender.DisplayMode = Microsoft.Windows.Controls.CalendarMode.Year;
}