1

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.

1

3 Answers 3

1
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.

Sign up to request clarification or add additional context in comments.

1 Comment

The Format and CustomFormat only exists in Windows Forms. WPF has no equivalent.
1

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

0

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;
}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.