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
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.
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
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'm not sure I follow the comparison to CalendarInfo. CalendarInfo exposed 2 selected date range collections - SelectedDateRanges and AlternateSelectedDateRanges. You would then tell which control which collection to use. These do not dictate what dates are in view nor is there any single collection on the CalendarInfo which indicates/aggregates what is in view on controls with which it is associated. Also there were limitations with regards to having a singular collection that we did not want to extend to the new controls. For example, in WinSchedule selecting dates in the monthviewsingle would change the visible dates displayed by the dayview. So if the end user was simply selecting multiple dates because they wanted to create an activity for those dates then that would automatically affect what dates were shown in the day view. With the xamSchedule controls the selection and what is shown by each is maintained by the control and so someone who wanted to synchronize the selection/visible dates could do so but at least for now would have to write their own attached behavior. In the future we could look to add a synchronization helper. If you would like to see this then please submit a feature request for this and try to provide as much information as possible about the use cases/scenarios so we can ensure that it meets the requirements of the most common situations.