用于UWP的Telerik UI RadCalendar控件绑定到选定的日期

问题描述 投票:0回答:1

在此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

如何在此控件上正确设置绑定?

telerik uwp-xaml
1个回答
0
投票

我可以看到ViewModel的selectedCalendarDateRange属性的类型与RadCalendar的SelectedDateRange属性的类型不匹配。请注意,SelectedDateRange的类型后面有一个问号。这使它成为可以为空的类型。您可以尝试在ViewModel中的属性类型后面添加相同的问号,如下所示:

  public CalendarDateRange?  selectedCalendarDateRange {get=>_calendarDateRange; set => SetProperty(ref _calendarDateRange,value); }

字段_calendarDateRange也应该可以为空。

© www.soinside.com 2019 - 2024. All rights reserved.