void CalendarEx_MouseDown(object sender, System.Windows.Input.MouseButtonEventArgs e) { CalendarDayButtonEx calendarDayButtonEx = sender as CalendarDayButtonEx; // MessageBox.Show(calendarDayButtonEx.IsThisMonth.ToString() + ThisMonth.ToString()); if (!calendarDayButtonEx.IsThisMonth) { int month = (int)cbb_month.SelectedValue; if (month == 1 && calendarDayButtonEx.SolarDateTime.Month == 12) { cbb_month.SelectedValue = 12; cbb_year.SelectedValue = calendarDayButtonEx.SolarDateTime.Year; } else if (month == 12 && calendarDayButtonEx.SolarDateTime.Month == 1) { cbb_month.SelectedValue = 1; cbb_year.SelectedValue = calendarDayButtonEx.SolarDateTime.Year; } else if (month > calendarDayButtonEx.SolarDateTime.Month) { cbb_month.SelectedValue = (int)cbb_month.SelectedValue - 1; } else if (month < calendarDayButtonEx.SolarDateTime.Month) { cbb_month.SelectedValue = (int)cbb_month.SelectedValue + 1; } // Combobox_SelectionChanged(null, null); } }
public CalendarEx() { InitializeComponent(); list = new List<HolidayArrangement>(); // List<DateTime> listHoliday = new List<DateTime>(); listWorkday = new List<DateTime>(); // listHoliday.Add(new DateTime(DateTime.Now.Year, 1, 1)); //dt[0] = DateTime.Now; listWorkday.Add(new DateTime(2014, 1, 26)); listWorkday.Add(new DateTime(2014, 2, 8)); listWorkday.Add(new DateTime(2014, 5, 4)); listWorkday.Add(new DateTime(2014, 9, 28)); listWorkday.Add(new DateTime(2014, 10, 1)); list.Add(new HolidayArrangement() { Name = "元旦", Holiday = new DateTime(DateTime.Now.Year, 1, 1), NumberOfDays = 1, Workday = listWorkday }); list.Add(new HolidayArrangement() { Name = "春节", Holiday = new DateTime(DateTime.Now.Year, 1, 31), NumberOfDays = 7, Workday = listWorkday }); Dictionary<int, string> year = new Dictionary<int, string>(); for (int i = 1901; i < 2049; i++) { year.Add(i, i + "年"); } cbb_year.SelectedValuePath = "Key"; cbb_year.DisplayMemberPath = "Value"; cbb_year.ItemsSource = year; Dictionary<int, string> month = new Dictionary<int, string>(); for (int i = 1; i <= 12; i++) { month.Add(i, i + "月"); } cbb_month.SelectedValuePath = "Key"; cbb_month.DisplayMemberPath = "Value"; cbb_month.ItemsSource = month; DateTime now = DateTime.Now; cbb_year.SelectedValue = now.Year; cbb_month.SelectedValue = now.Month; cbb_month.SelectionChanged += Combobox_SelectionChanged; cbb_year.SelectionChanged += Combobox_SelectionChanged; for (int i = 0; i < 6; i++) { for (int j = 0; j < 7; j++) { calendarDayButtons[i, j] = new CalendarDayButtonEx(); } } InitGrid(grid); }