private void daynew_Selected(object sender, DaySelectArgs e) { GeneralDay.Selected -= daynew_Selected; Day day = e.day; if (lastDay != null) { if (lastDay != day) { for (int i = 0; i < Days.Count; i++) { if (lastDay.SelectedDate.Month == Days[i].SelectedDate.Month) if (lastDay.SelectedDate.Day == Days[i].SelectedDate.Day) { lastDay = Days[i]; Days.RemoveAt(i); Days.Insert(i, lastDay); } } } } lastDay = day; OnDaySelected(day); }
private void OnDaySelected(Day day) { SelectedDateTime = day.SelectedDate; OnDateTimeSelected(SelectedDateTime); if (day.IsOtherMonth) { UpdateDays(SelectedDateTime); this.header.MonthTitle = day.SelectedDate.Month.ToString(); this.header.YearTitle = day.SelectedDate.Year.ToString(); this.MonthTitle = SelectedDateTime.Month; this.YearTitle = SelectedDateTime.Year; } }
private ObservableCollection<Day> CreateDay(DateTime date) { days.Clear(); time = date; DayOfWeek week = date.DayOfWeek; DateTime tempDateTime = new DateTime(date.Year, date.Month, 1); bool isinselected = false; if (ShowOtherMonth) { while (tempDateTime.DayOfWeek != DayOfWeek.Sunday) { tempDateTime = tempDateTime.AddDays(-1); GeneralSelectedAero(out isinselected, tempDateTime); GeneralDay = new Day() { SelectedDate = tempDateTime, CurrentDate = date, DefaultDate = date, DayForeground = GetDayForeBrush(tempDateTime, isOtherMonth: true), IsOtherMonth = true, DayStyle = DayStyle, IsInSelectedAero = isinselected }; GeneralDay.Selected += daynew_Selected; Days.Insert(0, GeneralDay); } } tempDateTime = new DateTime(date.Year, date.Month, 1); DateTime tempNextDateTime = DateTime.Now; if (date.Month != 12) tempNextDateTime = new DateTime(date.Year, date.Month + 1, 1); else tempNextDateTime = new DateTime(date.Year + 1, 1, 1); GeneralSelectedAero(out isinselected, tempDateTime); if (tempDateTime.Year == DateTime.Now.Year && tempDateTime.Month == DateTime.Now.Month) { GeneralDay = new Day() { CurrentDate = date, DefaultDate = date, SelectedDate = tempDateTime, DayForeground = GetDayForeBrush(tempDateTime), IsOtherMonth = false, DayStyle = DayStyle, IsInSelectedAero = isinselected }; GeneralDay.Selected += daynew_Selected; Days.Add(GeneralDay); } else { GeneralDay = new Day() { CurrentDate = date, DefaultDate = date, SelectedDate = tempDateTime, DayForeground = GetDayForeBrush(tempDateTime), IsOtherMonth = false, DayStyle = GetDayForeBrush(), IsInSelectedAero = isinselected }; GeneralDay.Selected += daynew_Selected; Days.Add(GeneralDay); } tempDateTime = tempDateTime.AddDays(1); while (tempDateTime < tempNextDateTime) { GeneralSelectedAero(out isinselected, tempDateTime); GeneralDay = new Day() { CurrentDate = date, DefaultDate = date, SelectedDate = tempDateTime, DayForeground = GetDayForeBrush(tempDateTime), IsOtherMonth = false, DayStyle = DayStyle, IsInSelectedAero = isinselected }; GeneralDay.Selected += daynew_Selected; Days.Add(GeneralDay); tempDateTime = tempDateTime.AddDays(1); } if (ShowOtherMonth) { if (date.Month != 12) tempNextDateTime = new DateTime(date.Year, date.Month + 1, 1); else tempNextDateTime = new DateTime(date.Year + 1, 1, 1); while (tempNextDateTime.DayOfWeek != DayOfWeek.Saturday) { GeneralSelectedAero(out isinselected, tempNextDateTime); GeneralDay = new Day() { SelectedDate = tempNextDateTime, CurrentDate = date, DefaultDate = date, DayForeground = GetDayForeBrush(tempNextDateTime, isOtherMonth: true), IsInSelectedAero = isinselected, IsOtherMonth = true, DayStyle = DayStyle }; GeneralDay.Selected += daynew_Selected; Days.Add(GeneralDay); tempNextDateTime = tempNextDateTime.AddDays(1); } GeneralSelectedAero(out isinselected, tempNextDateTime); GeneralDay = new Day() { SelectedDate = tempNextDateTime, CurrentDate = date, DefaultDate = date, DayForeground = GetDayForeBrush(tempNextDateTime, true), IsOtherMonth = true, DayStyle = DayStyle, IsInSelectedAero = isinselected }; GeneralDay.Selected += daynew_Selected; Days.Add(GeneralDay); } LayoutRoot.DataContext = this; return days; }