gpt4 book ai didi

c# - Message=SelectedDate 值无效

转载 作者:太空狗 更新时间:2023-10-29 23:09:24 26 4
gpt4 key购买 nike

我可能很累,但为什么会抛出异常:

 this.SomeDatePicker.SelectedDate = DateTime.Now.Date;

同样发生在:

 this.SomeDatePicker.SelectedDate = DateTime.Now;

错误信息是:

System.ArgumentOutOfRangeException was unhandled
Message=SelectedDate value is not valid.
Parameter name: d
Source=PresentationFramework
ParamName=d
StackTrace:
at System.Windows.Controls.Calendar.OnSelectedDateChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
at System.Windows.DependencyObject.OnPropertyChanged(DependencyPropertyChangedEventArgs e)
at System.Windows.FrameworkElement.OnPropertyChanged(DependencyPropertyChangedEventArgs e)
at System.Windows.DependencyObject.NotifyPropertyChange(DependencyPropertyChangedEventArgs args)
at System.Windows.DependencyObject.UpdateEffectiveValue(EntryIndex entryIndex, DependencyProperty dp, PropertyMetadata metadata, EffectiveValueEntry oldEntry, EffectiveValueEntry& newEntry, Boolean coerceWithDeferredReference, Boolean coerceWithCurrentValue, OperationType operationType)
at System.Windows.DependencyObject.SetValueCommon(DependencyProperty dp, Object value, PropertyMetadata metadata, Boolean coerceWithDeferredReference, Boolean coerceWithCurrentValue, OperationType operationType, Boolean isInternal)
at System.Windows.Controls.DatePicker.CoerceSelectedDate(DependencyObject d, Object value)
at System.Windows.DependencyObject.ProcessCoerceValue(DependencyProperty dp, PropertyMetadata metadata, EntryIndex& entryIndex, Int32& targetIndex, EffectiveValueEntry& newEntry, EffectiveValueEntry& oldEntry, Object& oldValue, Object baseValue, Object controlValue, CoerceValueCallback coerceValueCallback, Boolean coerceWithDeferredReference, Boolean coerceWithCurrentValue, Boolean skipBaseValueChecks)
at System.Windows.DependencyObject.UpdateEffectiveValue(EntryIndex entryIndex, DependencyProperty dp, PropertyMetadata metadata, EffectiveValueEntry oldEntry, EffectiveValueEntry& newEntry, Boolean coerceWithDeferredReference, Boolean coerceWithCurrentValue, OperationType operationType)
at System.Windows.DependencyObject.SetValueCommon(DependencyProperty dp, Object value, PropertyMetadata metadata, Boolean coerceWithDeferredReference, Boolean coerceWithCurrentValue, OperationType operationType, Boolean isInternal)
at System.Windows.DependencyObject.SetValue(DependencyProperty dp, Object value)
....

最佳答案

如果您设置的日期出现在 BlackoutDates 中,则会抛出该异常.

AddDaysInPast 方法应该等效于:

Add(new CalendarDateRange(DateTime.MinValue, DateTime.Today.AddDays(-1)));

因此,除非当前时间在调用 AddDaysInPastSelectedDate 分配之间发生变化,否则您应该不会遇到您描述的问题。

在调试中获取 BlackoutDates 中存在的完整范围并使用该信息更新您的问题,您可以使用类似的东西:

string ranges = string.Join(
Environment.NewLine,
DatePicker.BlackoutDates.Select(r => string.Concat(r.Start, "|", r.End)));

关于c# - Message=SelectedDate 值无效,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12114968/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com