private void BuildCalendarUI() { int iDaysInMonth = sysCal.GetDaysInMonth(_DisplayStartDate.Year, _DisplayStartDate.Month); int iOffsetDays = Convert.ToInt32(System.Enum.ToObject(typeof(System.DayOfWeek), _DisplayStartDate.DayOfWeek)); int iWeekCount = 0; WeekOfDaysControl weekRowCtrl = new WeekOfDaysControl(); MonthViewGrid.Children.Clear(); AddRowsToMonthGrid(iDaysInMonth, iOffsetDays); MonthYearLabel.Content = (new DateTimeFormatInfo()).GetMonthName(_DisplayMonth) + " " + _DisplayYear; //CultureInfo.CurrentUICulture.DateTimeFormat.MonthNames[i] for (int i = 1; i <= iDaysInMonth; i++) { if ((i != 1) && System.Math.IEEERemainder((i + iOffsetDays - 1), 7) == 0) { //-- add existing weekrowcontrol to the monthgrid Grid.SetRow(weekRowCtrl, iWeekCount); MonthViewGrid.Children.Add(weekRowCtrl); //-- make a new weekrowcontrol weekRowCtrl = new WeekOfDaysControl(); iWeekCount += 1; } //-- load each weekrow with a DayBoxControl whose label is set to day number DayBoxControl dayBox = new DayBoxControl(); dayBox.DayNumberLabel.Content = i.ToString(); dayBox.Tag = i; dayBox.MouseDoubleClick += DayBox_DoubleClick; //-- customize daybox for today: if ((new System.DateTime(_DisplayYear, _DisplayMonth, i)) == System.DateTime.Today) { dayBox.DayLabelRowBorder.Background = (Brush)dayBox.TryFindResource("OrangeGradientBrush"); dayBox.DayAppointmentsStack.Background = Brushes.Wheat; } //-- for design mode, add appointments to random days for show... if (System.ComponentModel.DesignerProperties.GetIsInDesignMode(this)) { if (Math.Round(1d) < 0.25) { DayBoxAppointmentControl apt = new DayBoxAppointmentControl(); apt.DisplayText.Text = "Apt on " + i + "th"; dayBox.DayAppointmentsStack.Children.Add(apt); } } else if (_monthAppointments != null) { //-- Compiler warning about unpredictable results if using i (the iterator) in lambda, the // "hint" suggests declaring another var and set equal to iterator var int iday = i; List <Appointment> aptInDay = _monthAppointments.FindAll(new System.Predicate <Appointment>((Appointment apt) => Convert.ToDateTime(apt.StartTime).Day == iday)); foreach (Appointment a in aptInDay) { DayBoxAppointmentControl apt = new DayBoxAppointmentControl(); apt.DisplayText.Text = a.Subject; apt.Tag = a.AppointmentID; apt.MouseDoubleClick += Appointment_DoubleClick; dayBox.DayAppointmentsStack.Children.Add(apt); } } Grid.SetColumn(dayBox, (i - (iWeekCount * 7)) + iOffsetDays); weekRowCtrl.WeekRowGrid.Children.Add(dayBox); } Grid.SetRow(weekRowCtrl, iWeekCount); MonthViewGrid.Children.Add(weekRowCtrl); }
private void BuildCalendarUI() { int iDaysInMonth = sysCal.GetDaysInMonth(_DisplayStartDate.Year, _DisplayStartDate.Month); int iOffsetDays = Convert.ToInt32(System.Enum.ToObject(typeof(System.DayOfWeek), _DisplayStartDate.DayOfWeek)); int iWeekCount = 0; WeekOfDaysControl weekRowCtrl = new WeekOfDaysControl(); MonthViewGrid.Children.Clear(); AddRowsToMonthGrid(iDaysInMonth, iOffsetDays); MonthYearLabel.Content = (new DateTimeFormatInfo()).GetMonthName(_DisplayMonth) + " " + _DisplayYear; //CultureInfo.CurrentUICulture.DateTimeFormat.MonthNames[i] for (int i = 1; i <= iDaysInMonth; i++) { if ((i != 1) && System.Math.IEEERemainder((i + iOffsetDays - 1), 7) == 0) { //-- add existing weekrowcontrol to the monthgrid Grid.SetRow(weekRowCtrl, iWeekCount); MonthViewGrid.Children.Add(weekRowCtrl); //-- make a new weekrowcontrol weekRowCtrl = new WeekOfDaysControl(); iWeekCount += 1; } //-- load each weekrow with a DayBoxControl whose label is set to day number DayBoxControl dayBox = new DayBoxControl(); dayBox.DayNumberLabel.Content = i.ToString(); dayBox.Tag = i; dayBox.MouseDoubleClick += DayBox_DoubleClick; //-- customize daybox for today: if ((new System.DateTime(_DisplayYear, _DisplayMonth, i)) == System.DateTime.Today) { dayBox.DayLabelRowBorder.Background = (Brush)dayBox.TryFindResource("OrangeGradientBrush"); dayBox.DayAppointmentsStack.Background = Brushes.Wheat; } //-- for design mode, add appointments to random days for show... if (System.ComponentModel.DesignerProperties.GetIsInDesignMode(this)) { if (Math.Round(1d) < 0.25) { DayBoxAppointmentControl apt = new DayBoxAppointmentControl(); apt.DisplayText.Text = "Apt on " + i + "th"; dayBox.DayAppointmentsStack.Children.Add(apt); } } else if (_monthAppointments != null) { //-- Compiler warning about unpredictable results if using i (the iterator) in lambda, the // "hint" suggests declaring another var and set equal to iterator var int iday = i; List<Appointment> aptInDay = _monthAppointments.FindAll(new System.Predicate<Appointment>((Appointment apt) => Convert.ToDateTime(apt.StartTime).Day == iday)); foreach (Appointment a in aptInDay) { DayBoxAppointmentControl apt = new DayBoxAppointmentControl(); apt.DisplayText.Text = a.Subject; apt.Tag = a.AppointmentID; apt.MouseDoubleClick += Appointment_DoubleClick; dayBox.DayAppointmentsStack.Children.Add(apt); } } Grid.SetColumn(dayBox, (i - (iWeekCount * 7)) + iOffsetDays); weekRowCtrl.WeekRowGrid.Children.Add(dayBox); } Grid.SetRow(weekRowCtrl, iWeekCount); MonthViewGrid.Children.Add(weekRowCtrl); }