Telerik UI For UWP Привязка элемента управления RadCalendar к выбранным датам - PullRequest
0 голосов
/ 14 февраля 2019

В этом документе 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

Как правильно настроить привязку для этого элемента управления?

1 Ответ

0 голосов
/ 15 февраля 2019

Я вижу, что тип свойства selectedCalendarDateRange вашей ViewModel не соответствует типу свойства SelectedDateRange RadCalendar.Обратите внимание, что после типа SelectedDateRange есть знак вопроса.Это делает его обнуляемым типом.Вы можете попробовать добавить тот же знак вопроса после типа свойства в вашей ViewModel, например:

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

Поле _calendarDateRange также должно иметь значение null.

...