/// <summary> /// Clears all colors in the CalendarMonth /// </summary> public void ClearAllDayColors() { CalendarDay today = null; // first clear the today object if it exists. it will be reset later ClearToday(); // clear each day unless it's today and reset it foreach (CalendarDay day in _coloredDays) { if (CalendarDay.IsToday(day)) { today = day; } else { day.DayText = string.Empty; day.DayColor = Utilities.Helpers.Colors.LightGray; day.SetAllText(Utilities.Helpers.Colors.Gray); } } // set the today calendarDay if (today != null) { SetToday(today); } }
/// <summary> /// Sets the input calendar day to today /// </summary> /// <param name="cd">the input calendarday</param> private void SetToday(CalendarDay cd) { cd.DayText = TODAY_STRING; cd.DayColor = Utilities.Helpers.Colors.Gray; cd.SetAllText(Utilities.Helpers.Colors.White); _today = cd; _coloredDays.Add(_today); }
/// <summary> /// Sets the color of the specified day in the current CalendarMonth /// </summary> /// <param name="Year">The input year</param> /// <param name="Month">The input month</param> /// <param name="Day">The input day</param> /// <param name="Color">The color to set to</param> public void SetDayColor(int Year, int Month, int Day, Utilities.Helpers.Colors Color) { if (ContainsDay(Year, Month, Day)) { CalendarDay cd = _calendarDays[GetCalendarDayGUID(Year, Month, Day)]; cd.DayColor = Color; cd.SetAllText(Utilities.Helpers.Colors.White); _coloredDays.Add(cd); } }
public void NormalView() { for (int i = 0; i < _calendarDays.Count; i++) { CalendarDay cd = _calendarDays.ElementAt(i).Value; cd.NormalView(); } for (int i = 0; i < _headerDays.Count; i++) { CalendarDay cd = _headerDays.ElementAt(i); cd.NormalView(); } }
public static bool IsToday(CalendarDay day) { try { if (day._year == DateTime.Today.Year && day._month == DateTime.Today.Month && day._day == DateTime.Today.Day) { return(true); } } catch { } return(false); }
public CalendarMonth(int year, int month) { this.InitializeComponent(); this._calendarDays = new Dictionary <string, CalendarDay>(); this._coloredDays = new List <CalendarDay>(); this._headerDays = new List <CalendarDay>(); this.Year = year; this.Month = month; int days = DateTime.DaysInMonth(year, month); DateTime firstActualDayOfMonth = new DateTime(year, month, 1); // Since the first day of the month could be in the middle of the week, we'll still need to // add in days for the preivous month which go before it DateTime startingDayOfCalMonth = firstActualDayOfMonth.AddDays( numDayOfWeek(new DateTime(year, month, 1).DayOfWeek) * -1 // multiply by -1 to subtract ); DateTime currentDayOfCalMonth = startingDayOfCalMonth; for (int i = 0; i < ROWS; i++) { for (int j = 0; j < COLS; j++) { CalendarDay cd = new CalendarDay(currentDayOfCalMonth.Year, currentDayOfCalMonth.Month, currentDayOfCalMonth.Day); cd.SetValue(Grid.RowProperty, i); cd.SetValue(Grid.ColumnProperty, j); // if we're doing the days row if (i == 0) { DayOfWeek nextday = (DayOfWeek)j; cd.DayText = nextday.ToString(); cd.DayValueSnapped = nextday.ToString().Substring(0, 3); // add the three letter rep of the day cd.IsDayHeader(); _headerDays.Add(cd); } // if we're no longer on the rows with the days "Sun --> Sat" else { cd.DayValue = currentDayOfCalMonth.Day.ToString(); // if the current day is in the past month if (currentDayOfCalMonth.Month != month) { cd.IsGrayed = true; } // if this is today if (CalendarDay.IsToday(cd)) { SetToday(cd); } // add to internal Dictionary _calendarDays.Add(GetCalendarDayGUID(currentDayOfCalMonth.Year, currentDayOfCalMonth.Month, currentDayOfCalMonth.Day), cd); // increment days currentDayOfCalMonth = currentDayOfCalMonth.AddDays(1); } // add to UI CalendarMonthGrid.Children.Add(cd); } } }