Hi, since I use MVVM I would like to databind the VisibleDates property from my ViewModel class.Apparently there is no such possibility.Being accustomed to use the CalendarInfo I would have expected a similar functionality: one single place to select a single date, a continous daterange, or a List<DateRange>. Then the various controls (XamDayView, XamMonthCalendar) would reflect automatically those changes in the VisibleDates and SelectedDates respectively.Is there a way to obtain such functionality?Best Regards
Hello,
I am just checking if you need any further clarification on the matter.
If the above suggestion helped you solve your issue please verify the thread as answered so other users may take better advantage of it.
Sincerely,Petar MonovDeveloper Support EngineerInfragistics Bulgariawww.infragistics.com/support
I found a workaround:
although I'd prefer to drive everything from a ViewModel I had to spread the logic in the code behind
XAML
<igEditors:XamMonthCalendar x:Name="monthCalendar" SelectedDatesChanged="monthCalendar_SelectedDatesChanged"
<ig:XamDayView attach:XamDayViewHelper.VisibleDates="{Binding Path=VisibleDates}"
CODE BEHIND
avm = new AgendaViewModel(); DataContext = avm;
private void monthCalendar_SelectedDatesChanged(object sender, Infragistics.Windows.Editors.Events.SelectedDatesChangedEventArgs e) { List<DateTime> tmpDates = new List<DateTime>(); XamMonthCalendar monthCalendar = sender as XamMonthCalendar; if (monthCalendar != null) { switch (avm.AgendaSituation) { case AgendaSituation.SingleOperator: monthCalendar.SelectionType = SelectionType.Extended; break; case AgendaSituation.MultipleOperator: case AgendaSituation.DentalChair: default: monthCalendar.SelectionType = SelectionType.Single; break; } foreach (var item in monthCalendar.SelectedDates) { tmpDates.Add(item); } } avm.VisibleDates = tmpDates;
}
where VisibleDates is public static class XamDayViewHelper
{ public static readonly DependencyProperty VisibleDatesProperty = DependencyProperty.RegisterAttached("VisibleDates", typeof(IList<DateTime>), typeof(XamDayViewHelper), new FrameworkPropertyMetadata(null, new PropertyChangedCallback(VisibleDatesChanged))); private static void VisibleDatesChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e) { XamDayView dv = sender as XamDayView; if (dv != null) { dv.VisibleDates.Clear(); foreach (var day in e.NewValue as IList<DateTime>) { dv.VisibleDates.Add(day); } } } public static IList<DateTime> GetVisibleDates(DependencyObject obj) { return (IList<DateTime>)obj.GetValue(VisibleDatesProperty); } public static void SetVisibleDates(DependencyObject obj, IList<DateTime> value) { obj.SetValue(VisibleDatesProperty, value); } }I don't understand why you have a SelectedDatesChanged event and do not a SelectedDates bindable property that I could read from or write to using a ViewModel.It works for my needs.Best Regards Roberto Dalmonte
Hi Roberto,
I am really glad you was able to work this out and thank you for sharing your approach. This is sure to help other user who are facing this.
Best regards Petar.