在此Telerik文档中:
https://docs.telerik.com/devtools/universal-windows-platform/controls/radcalendar/selection
它说:
Properties
SelectedDateRange (CalendarDateRange?): Gets or sets the first date range in
the current selection or returns null if the selection is empty. Setting this
property in a calendar that supports multiple selections clears existing
selected ranges and sets the selection to the range specified.
SelectedDateRanges (CalendarDateRangeCollection): Holds a collection of all
selection ranges.
我在绑定日历时遇到麻烦,我对要求有误解,并且没有任何示例。我正在使用ViewModel方法。我的XAML:
<input:RadCalendar
Name="cal"
SelectedDateRange="{x:Bind viewModel.selectedCalendarDateRange, Mode=TwoWay}"
SelectionMode="Multiple"
<input:RadCalendar.ContextFlyout>
<MenuFlyout>
<MenuFlyoutItem Command="{x:Bind viewModel.calendarSelectCommand}">OK</MenuFlyoutItem>
</MenuFlyout>
</input:RadCalendar.ContextFlyout>
在我的ViewModel中:
public CalendarDateRange? selectedCalendarDateRange {get=>_calendarDateRange;
set => SetProperty(ref _calendarDateRange,value); }
我正在选择一些日期,并且在鼠标悬停时出现此错误:
System.ArgumentOutOfRangeException: The added or subtracted value results in
an un-representable DateTime.
Parameter name: value
at System.DateTime.AddTicks(Int64 value)
at Telerik.UI.Xaml.Controls.Input.CalendarDateRange.
IntersectsWithRange(CalendarDateRange otherDateRange)
at Telerik.UI.Xaml.Controls.Input.
CalendarDateRangeCollection.MergeCollidingRanges
(CalendarDateRange newDataRange, Int32 currentIndex)
at Telerik.UI.Xaml.Controls.Input.
CalendarDateRangeCollection.AddDateRange(CalendarD
如何在此控件上正确设置绑定?
答案 0 :(得分:0)
我看到ViewModel的 selectedCalendarDateRange 属性的类型与RadCalendar的 SelectedDateRange 属性的类型不匹配。请注意,SelectedDateRange的类型后面有一个问号。这使其成为可为空的类型。您可以尝试在ViewModel中的属性类型之后添加相同的问号,如下所示:
public CalendarDateRange? selectedCalendarDateRange {get=>_calendarDateRange; set => SetProperty(ref _calendarDateRange,value); }
字段 _calendarDateRange 也应该可以为空。