Home > Software engineering >  How Can I Disable Year Selection in WPF Calendar
How Can I Disable Year Selection in WPF Calendar

Time:03-05

  • I want to make a calendar like Google's Calendar to Show all days of the year in one screen.
    • I will use 12 Calendar instances.
  • I want To disable the year selection from the header of the WPF Calendar to look like a label, rather than a clickable button.

WPF Calendar

CodePudding user response:

You can do this by setting the DisplayDateStart and the DisplayDateEnd properties of The Calender Control.

For example in XAML, you could do:

<Calendar DisplayDateStart="1/1/2022" DisplayDateEnd="31/12/2022"/>

Or in code-behind:

Calendar cal = new Calendar();
cal.DisplayDateStart = new DateTime(2022, 1, 1);
cal.DisplayDateEnd = new DateTime(2022, 12, 31);

Limitations: This only restricts the display range, as pointed out int the comment.

CodePudding user response:

I did it by setting "IsHitTestVisible" = false to "PART_HeaderButton" in the Control Template. this is the Control template Which i used

Calendar Control Template

  • Related