private void SetMonthModeCalendarDayButtons()
{
DateTime firstDayOfMonth = DateTimeHelper.DiscardDayTime(DisplayDate);
int lastMonthToDisplay = GetNumberOfDisplayedDaysFromPreviousMonth(firstDayOfMonth);
bool isMinMonth = DateTimeHelper.CompareYearMonth(firstDayOfMonth, DateTime.MinValue) <= 0;
bool isMaxMonth = DateTimeHelper.CompareYearMonth(firstDayOfMonth, DateTime.MaxValue) >= 0;
int daysInMonth = _calendar.GetDaysInMonth(firstDayOfMonth.Year, firstDayOfMonth.Month);
CultureInfo culture = DateTimeHelper.GetCulture(this);
int count = ROWS * COLS;
for (int childIndex = COLS; childIndex < count; childIndex++)
{
CalendarDayButton childButton = _monthView.Children[childIndex] as CalendarDayButton;
Debug.Assert(childButton != null);
int dayOffset = childIndex - lastMonthToDisplay - COLS;
if ((!isMinMonth || (dayOffset >= 0)) && (!isMaxMonth || (dayOffset < daysInMonth)))
{
DateTime dateToAdd = _calendar.AddDays(firstDayOfMonth, dayOffset);
SetMonthModeDayButtonState(childButton, dateToAdd);
childButton.DataContext = dateToAdd;
childButton.SetContentInternal(DateTimeHelper.ToDayString(dateToAdd, culture));
}
else
{
SetMonthModeDayButtonState(childButton, null);
childButton.DataContext = null;
childButton.SetContentInternal(DateTimeHelper.ToDayString(null, culture));
}
}
}