Problem with DisplayMode calendar. By default everything is fine

enter image description here

But when the DisplayMode property changes to any state, it expands beyond the window and, it seems, the universe.

enter image description here

How can this be cured? I tried to set the property in the code, maxWidth , but also did not save.

  • in which container it lies with you? - Gardes
  • @Gardes Anywhere this behavior, tried and in StackPanel, and in DockPanel and just out the window, everything is the same - dmepty
  • Can not play, can you drop the markup? - Gardes
  • @Gardes markup is terribly primitive) <Calendar DisplayMode = "Decade"> </ Calendar> - dmepty
  • one
    sometimes a fresh look can see the problem under the nose) - Gardes

1 answer 1

Judging by the numerous similar questions on enSO, this is either a bug or a feature related to the fact that the calendar was designed to be placed in pop-up elements, it is possible that the calendar control was created only for use inside DatePicker and the developers did not provide for its independent use (see also this question: Problem with processing a click on a WPF calendar )

As a solution, do not set the DisplayMode in XAML, but do it after downloading:

 <Calendar Loaded="Calendar_Loaded"/> 

and:

 private void Calendar_Loaded(object sender, RoutedEventArgs e) { ((Calendar)sender).DisplayMode = CalendarMode.Decade; } 
  • And it really worked. I installed DisplayMode on the window load event and did not start. Thank! - dmepty
  • Although the window loading should work too (this event is triggered when all the controls are loaded), it is better to load the control. Well, if you wish, you can make an heir to the Calendar and implement it in it so that you can use it in any window or container or template or other. Without thinking - Andrey NOP