private void PopulateGrids() { if (_monthGrid != null) { for (int i = 0; i < COLS; i++) { if (_dayTitleTemplate != null) { FrameworkElement cell = (FrameworkElement)this._dayTitleTemplate.LoadContent(); cell.SetValue(Grid.RowProperty, 0); cell.SetValue(Grid.ColumnProperty, i); this._monthGrid.Children.Add(cell); } } for (int i = 1; i < ROWS; i++) { for (int j = 0; j < COLS; j++) { DayButton cell = new DayButton(); cell.SetValue(Grid.RowProperty, i); cell.SetValue(Grid.ColumnProperty, j); ((DayButton)cell).Click += new RoutedEventHandler(Cell_Click); if (_owner.DayStyle != null) { cell.Style = _owner.DayStyle; } this._monthGrid.Children.Add(cell); } } } if (_yearViewGrid != null) { MonthButton month; int count = 0; for (int i = 0; i < YEAR_ROWS; i++) { for (int j = 0; j < YEAR_COLS; j++) { month = new MonthButton(); month.SetValue(Grid.RowProperty, i); month.SetValue(Grid.ColumnProperty, j); month.MouseLeftButtonUp += new MouseButtonEventHandler(Month_MouseLeftButtonUp); if (_owner.MonthStyle != null) { month.Style = _owner.MonthStyle; } this._yearViewGrid.Children.Add(month); count++; } } } }
private static void EnsureMonthStyle(MonthButton month, Style oldCalendarMonthStyle, Style newCalendarMonthStyle) { Debug.Assert(month != null); if (newCalendarMonthStyle != null) { // if (month != null && (month.Style == null || month.Style == oldCalendarMonthStyle)) { month.Style = newCalendarMonthStyle; } } }
public void UpdateYearMode() { Debug.Assert(this._owner.SelectedMonth != null); _currentMonth = (DateTime)_owner.SelectedMonth; _firstDayOfWeek = _owner.FirstDayOfWeek; if (_currentMonth != null) { if (this._headerButton != null) { this._headerButton.Content = _currentMonth.Year.ToString(CultureInfo.CurrentCulture); this._headerButton.IsEnabled = false; } int count = 0; int year = _calendar.GetYear(_currentMonth); // check to see if Prev/Next Buttons will be displayed if (_previousButton != null) { if (_owner.DisplayDateStart.GetValueOrDefault(DateTime.MinValue).Year == year) { _previousButton.IsEnabled = false; } else { _previousButton.IsEnabled = true; } } if (_nextButton != null) { if (_owner.DisplayDateEnd.GetValueOrDefault(DateTime.MaxValue).Year == year) { _nextButton.IsEnabled = false; } else { _nextButton.IsEnabled = true; } } if (_yearViewGrid != null) { foreach (object child in _yearViewGrid.Children) { MonthButton mybutton = child as MonthButton; Debug.Assert(mybutton != null); DateTime day = new DateTime(year, count + 1, 1, 1, 1, 1); mybutton.DataContext = day; mybutton.Content = CultureInfo.CurrentCulture.DateTimeFormat.AbbreviatedMonthNames[count]; mybutton.Visibility = Visibility.Visible; if (day.Year == _currentMonth.Year && day.Month == _currentMonth.Month && day.Day == _currentMonth.Day) { mybutton.IsFocusedOverride = true; } else { mybutton.IsFocusedOverride = false; } if (_owner.SelectedDate != null) { if (CompareYearMonth(day, (DateTime)_owner.SelectedDate) == 0) { mybutton.IsSelected = true; } else { mybutton.IsSelected = false; } } if (CompareYearMonth(day, _owner.DisplayDateStart.GetValueOrDefault(DateTime.MinValue)) < 0 || CompareYearMonth(day, _owner.DisplayDateEnd.GetValueOrDefault(DateTime.MaxValue)) > 0) { mybutton.IsEnabled = false; mybutton.Opacity = 0; } else { mybutton.IsEnabled = true; mybutton.Opacity = 1; } count++; } } } }