// handler: OnCalendarButtonPressed
 internal void OnCalendarButtonPressed(MonthYearButton b, bool switchDisplayMode) {
     if (!(b.DataContext is DateTime))
         return;
     var requestedDate = (DateTime)b.DataContext;
     var result = new DateTime?();
     var calendarMode = CalendarMode.Month;
     switch (DisplayMode) {
         case CalendarMode.Year:
             result = Engine.SetYearMonth(DisplayDate, requestedDate);
             calendarMode = CalendarMode.Month;
             break;
         case CalendarMode.Decade:
             result = Engine.SetYear(DisplayDate, requestedDate);
             calendarMode = CalendarMode.Year;
             break;
     }
     if (!result.HasValue)
         return;
     DisplayDate = result.Value;
     if (!switchDisplayMode)
         return;
     SetCurrentValue(DisplayModeProperty, calendarMode);
     FocusDate(DisplayMode == CalendarMode.Month ? CurrentDate : DisplayDate);
 }
 private void PopulateDecadeViewGrid() {
     if (_decadeView == null)
         return;
     for (var row = 0; row < 3; ++row) {
         for (var column = 0; column < 4; ++column) {
             var cb = new MonthYearButton { Owner = Owner };
             cb.SetValue(Grid.RowProperty, row);
             cb.SetValue(Grid.ColumnProperty, column);
             cb.SetBinding(StyleProperty, GetOwnerBinding(Calendar.MonthYearButtonStyleProperty));
             cb.AddHandler(MouseLeftButtonDownEvent, new MouseButtonEventHandler(Year_MouseLeftButtonDown), true);
             cb.AddHandler(MouseLeftButtonUpEvent, new MouseButtonEventHandler(MonthOrYear_MouseLeftButtonUp), true);
             cb.AddHandler(MouseEnterEvent, new MouseEventHandler(Year_MouseEnter), true);
             cb.AddHandler(PreviewKeyDownEvent, new RoutedEventHandler(DayOrMonthOrYear_PreviewKeyDown), true);
             cb.Click += MonthOrYear_Clicked;
             _decadeView.Children.Add(cb);
         }
     }
 }