Ejemplo n.º 1
0
 private void PopulateMonths()
 {
     FireRegisterCalendarCellItem(false);
     grd.Children.Clear();
     grd.RowDefinitions.Clear();
     grd.ColumnDefinitions.Clear();
     AddColumns(4);
     int month = 1;
     if (_dayItems != null)
         _dayItems.Clear();
     for (int row = 0; row < 3; row++)
     {
         grd.RowDefinitions.Add(new RowDefinition());
         for (int col = 0; col < 4; col++)
         {
             var dayItem = new CalendarDayItem(2) { Width = _cellWidth, Height = CELL_HEIGHT };
             dayItem.DayButton.Content = GetMonthName((MonthNameType)month);
             dayItem.DayButton.Tag = month;
             dayItem.DayButton.IsChecked = month == _currentMonth;
             dayItem.Click += DayButtonClick;
             dayItem.SetValue(Grid.ColumnProperty, col);
             dayItem.SetValue(Grid.RowProperty, row);
             grd.Children.Add(dayItem);
             month++;
             _dayItems.Add(dayItem);
         }
     }
     FireRegisterCalendarCellItem(true);
 }
Ejemplo n.º 2
0
 private void PopulateYears()
 {
     FireRegisterCalendarCellItem(false);
     grd.Children.Clear();
     grd.RowDefinitions.Clear();
     grd.ColumnDefinitions.Clear();
     AddColumns(5);
     int year = _currentYear - 12;
     if (_dayItems != null)
         _dayItems.Clear();
     for (int row = 0; row < 5; row++)
     {
         grd.RowDefinitions.Add(new RowDefinition());
         for (int col = 0; col < 5; col++)
         {
             var dayItem = new CalendarDayItem(2) { Width = _cellWidth, Height = CELL_HEIGHT };
             dayItem.DayButton.Content = year;
             dayItem.DayButton.IsChecked = year == _currentYear;
             dayItem.DayButton.Tag = year;
             dayItem.Click += DayButtonClick;
             dayItem.SetValue(Grid.ColumnProperty, col);
             dayItem.SetValue(Grid.RowProperty, row);
             grd.Children.Add(dayItem);
             year++;
             _dayItems.Add(dayItem);
         }
     }
     FireRegisterCalendarCellItem(true);
 }
Ejemplo n.º 3
0
        private void PopulateDays()
        {
            FireRegisterCalendarCellItem(false);
            grd.Children.Clear();
            grd.RowDefinitions.Clear();
            grd.ColumnDefinitions.Clear();
            AddColumns(7);
            var totalDays = DateTime.DaysInMonth(_currentYear, _currentMonth);
            var dateTime = new DateTime(_currentYear, _currentMonth, 1);
            int col = (int)dateTime.DayOfWeek, row = -1;
            var day = 1;
            if (_dayItems != null)
                _dayItems.Clear();
            while (day <= totalDays)
            {
                grd.RowDefinitions.Add(new RowDefinition());
                row++;
                int index = 0;
                while (index < 7)
                {
                    var dayItem = new CalendarDayItem(1.5) { Width = _cellWidth, Height = CELL_HEIGHT };
                    if (index == col && day <= totalDays)
                    {
                        dayItem.DayButton.Content = day;
                        dayItem.DayButton.IsChecked = day == _currentDay;
                        dayItem.Click += DayButtonClick;
                        _dayItems.Add(dayItem);
                        day++;
                        col++;
                    }
                    else
                    {
                        dayItem.DayButton.Visibility = Visibility.Hidden;
                    }
                    dayItem.SetValue(Grid.ColumnProperty, index);
                    dayItem.SetValue(Grid.RowProperty, row);
                    grd.Children.Add(dayItem);

                    index++;
                }
                col = 0;
            }
            FireRegisterCalendarCellItem(true);
        }