private void ComboBoxDropDownClosed_Solar(object sender, object e) { int solarYear = comboBoxYears.SelectedIndex + 1970; int solarMonth = comboBoxMonths.SelectedIndex + 1; int solarDay = comboBoxDays.SelectedIndex + 1; DateTime dateTime = new DateTime(solarYear, solarMonth, solarDay); Refresh(dateTime); int lunarMonthDays = LunarCalendar.DaysOfLunarMonth(solarYear, solarMonth); if (lunarMonthDays == 29) { comboBoxLunarDays.ItemsSource = datas29LunarDays; }//if else { comboBoxLunarDays.ItemsSource = datas30LunarDays; }//else int daysOfSolarMonth = DaysOfSolarMonth(solarYear, solarMonth); switch (daysOfSolarMonth) { case 28: comboBoxDays.ItemsSource = datas28Days; break; case 29: comboBoxDays.ItemsSource = datas29Days; break; case 30: comboBoxDays.ItemsSource = datas30Days; break; case 31: comboBoxDays.ItemsSource = datas31Days; break; default: break; } comboBoxDays.SelectedIndex = solarDay - 1; int lunarYear = LunarCalendar.GetLunarYear(solarYear, solarMonth, solarDay); string lunarMonth = LunarCalendar.GetStringLunarMonth(solarYear, solarMonth, solarDay); int lunarDay = LunarCalendar.GetIntLunarDay(solarYear, solarMonth, solarDay); comboBoxLunarYears.SelectedItem = $"{lunarYear}年"; comboBoxLunarMonths.SelectedItem = lunarMonth; comboBoxLunarDays.SelectedIndex = lunarDay - 1; TextBlock_loaded(); }
private void Button_Click(object sender, RoutedEventArgs e) { Button b = (Button)sender; if (priClickButton != null) { priClickButton.BorderBrush = brushTransparent; } b.BorderBrush = brushBrown; priClickButton = b; int i = b.Name[b.Name.Length - 2] - '0'; int j = b.Name[b.Name.Length - 1] - '0'; int d = dayInButton[i, j];//该按钮显示的天数 //更新显示的日期 comboBoxDays.SelectedIndex = d - 1; int solarYear = comboBoxYears.SelectedIndex + 1970; int solarMonth = comboBoxMonths.SelectedIndex + 1; int solarDay = comboBoxDays.SelectedIndex + 1; DateTime dateTime = new DateTime(solarYear, solarMonth, solarDay); int lunarMonthDays = LunarCalendar.DaysOfLunarMonth(solarYear, solarMonth); if (lunarMonthDays == 29) { comboBoxLunarDays.ItemsSource = datas29LunarDays; }//if else { comboBoxLunarDays.ItemsSource = datas30LunarDays; }//else int lunarYear = LunarCalendar.GetLunarYear(solarYear, solarMonth, solarDay); string lunarMonth = LunarCalendar.GetStringLunarMonth(solarYear, solarMonth, solarDay); int lunarDay = LunarCalendar.GetIntLunarDay(solarYear, solarMonth, solarDay); comboBoxLunarYears.SelectedItem = $"{lunarYear}年"; comboBoxLunarMonths.SelectedItem = lunarMonth; comboBoxLunarDays.SelectedIndex = lunarDay - 1; TextBlock_loaded(); }