private static void SelectedDateTimeChangedCallback(DependencyObject d, DependencyPropertyChangedEventArgs e) { CustomDateTimePicker host = d as CustomDateTimePicker; if (e.NewValue is DateTime dt) { host.SelectedDate = dt.Date; host.SelectedTime = dt.TimeOfDay; } }
/// <summary> /// 控件的单个时间参数被修改时触发(时、分、秒) /// </summary> private static void TimeParamChangedCb(DependencyObject d, DependencyPropertyChangedEventArgs e) { CustomDateTimePicker host = d as CustomDateTimePicker; if (host._IsUpdatingTime) { return; } //设置控件的时间属性 host.SelectedTime = new TimeSpan(host.Hour, host.Minute, host.Second); }
//时间值变化 private static void SelectedTimeChangedCb(DependencyObject d, DependencyPropertyChangedEventArgs e) { CustomDateTimePicker host = (CustomDateTimePicker)d; TimeSpan ts = (TimeSpan)e.NewValue; host._IsUpdatingTime = true; host.Hour = ts.Hours; host.Minute = ts.Minutes; host.Second = ts.Seconds; host._IsUpdatingTime = false; host.UpdateSelectedDateTime(); }
//日期值变化 private static void SelectedDateChangedCb(DependencyObject d, DependencyPropertyChangedEventArgs e) { CustomDateTimePicker host = (CustomDateTimePicker)d; DateTime dt = (DateTime)e.NewValue; host._IsUpdatingDate = true; host.Year = dt.Year; host.Month = dt.Month; host.Day = dt.Day; host._IsUpdatingDate = false; host.UpdateSelectedDateTime(); }
//Update Date when date param updated /// <summary> /// 控件的单个日期参数被修改时触发(年、月、日) /// </summary> private static void DateParamChangedCb(DependencyObject d, DependencyPropertyChangedEventArgs e) { CustomDateTimePicker host = d as CustomDateTimePicker; if (host._IsUpdatingDate) { return; } var dayInMonth = DateTime.DaysInMonth(host.Year, host.Month); //设置控件的日期属性 host.SelectedDate = new DateTime(host.Year, host.Month, Math.Min(host.Day, dayInMonth)); }