I would be useful for MVVM to be able to bind the VisibleDates property to an ObservableCollection. Any reason why this can't be done?
Yes as the user navigates the control with the keyboard (e.g. use the right arrow key in dayview to navigate to the next day) or uses the scrollbar in xamMonthView, the VisibleDates are updated to reflect the dates that are displayed by the control. Also depending upon properties you change on the control, the VisibleDates may change (e.g. changing the WeekMode for schedule/day view).
From the snippet you provided it looks like you are just looking to have a "one-time" binding since your collection will not be updated as the user scrolls nor will the control be updated if you change the contents of that collection. If you want to keep the two in sync then you would have to hook the control's VisibleDates collection and the collection you set in that property and keep the two in sync similar to what I described in my previous response.
I didn't know there were any ways of manipulating the dates shown via the control, but anyway I managed it with an attached property
public static class DayViewHelper { public static readonly DependencyProperty VisibleDatesProperty = DependencyProperty.RegisterAttached("VisibleDates", typeof(IList<DateTime>), typeof(DayViewHelper), 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); } }
It wouldn't make sense for this to be a dependency property. The control needs to be able to manipulate the collection as the user navigates. In this sense it really is no different than dealing with the SelectedItems of any Selector which is also not bindable. I think if you want to maintain some connection between your view model and the visible dates then you would have to create an attached behavior. I.e. create an attached property that is provided the collection to synchronize with the visible dates and hook the CollectionChanged of the VisibleDates and your collection.. Whenever you get a change notification from one of them, asynchronously modify the other collection so they are in sync. You'll have to put in antirecursion logic so you don't try to resync while you are manipulating the contents of the other collection.
In the examples where it shows multiple days it's demonstrated by clearing the VisibleDates property on the schedule and then repopulating it using the collection .Add() syntax.
The problem is this property is not a dependency property and I cannot bind to it in the XAML.
Hello Geoff,
I have been looking into your request and although I am not quite sure what you mean by that I doubt that it is impossible. Usually this is a read-only property which gives you access to the days within the control and like other functionality and feature is decided on based mostly on popular demand along with other implementation criteria.
Here is the page where all our clients can influence/contribute to our product line: http://devcenter.infragistics.com/Protected/RequestFeature.aspx . If your suggestion is picked up for development you’ll be notified with an email.
Please let me know if you require any further assistance on the matter.
Sincerely,
Petar Monov
Developer Support Engineer
Infragistics Bulgaria
www.infragistics.com/support