Hi,
I am using XamScheduleDataManager and create my resources and resourcecalendars in my view model and bind these fine. I want to dynamically create my calendar groups and bind them as I do with my resources etc. The only examples I have found is to do it in the code behind of the view but I want to do it via the view model is this possible.
Hello Anne,
I have been looking into your question and I can suggest your look through the Mihail’s blog about using XamSchedule :
http://ko.infragistics.com/community/blogs/mihail_mateev/archive/2010/10/25/how-to-use-infragistics-xamschedule-solution.aspx
in order to see how he adds the calendar groups in his ScheduleViewModel. It seems that this is the best approach I can suggest.
Let me know, if you need any further assistance on this matter.
This example creates the calendar groups in the code behind of the view, it does not bind it via the view model.
Thank you for your reply. Currently this is the best way for using CalendarGroups in XamSchedule.
Let me know, if I can assist you with anything else on this matter.
I have managed to do this without adding code behind simply by adding event trigger to load of source. I have another question though, how can I set the background of the time slots, to be a different colour. e.g. 10:00 to 13:00 pink, 13:00 to 17:00 blue etc.
Would you please post code snippet for event trigger? Thanks
Hello Alex,
I have been looking into your post and would you please explain what code snippet you want exactly ?
If it is not regarding the discussed topic, please create a new thread.
Hi Alex,
Here is the code for the event trigger, this is put in the xaml
</ig:XamScheduleDataManager>
......... all the usual stuff here
<ei:Interaction.Triggers> <ei:EventTrigger EventName="Loaded"> <ei:InvokeCommandAction Command="{Binding CalendarLoadedCommand}" CommandParameter="{Binding CalendarGroups, ElementName=DataManager}"/> </ei:EventTrigger> </ei:Interaction.Triggers>
In the view model you have the following
public ICommand CalendarLoadedCommand { get { if (_calendarLoadedCommand == null) { _calendarLoadedCommand = new RelayCommand( param => CalendarLoaded(param) ); } return _calendarLoadedCommand; } }
Then the method called by command, retrieves param and stores to local variable
private CalendarGroupCollection _calendarGroups = new CalendarGroupCollection();
private void CalendarLoaded(object param) { _calendarGroups = (CalendarGroupCollection)param; }
And then I have a method which is called by my code where I need to create the groups and all it does is add it to this private collection and that's it job done.
private void CreateCalendarGroups(ResourceCalendar calendar) { CalendarGroup groupWithCalendarAdded = _calendarGroups.FirstOrDefault(cg => cg.Calendars.Contains(calendar)); if (groupWithCalendarAdded != null) { groupWithCalendarAdded.Calendars.Remove(calendar); if (groupWithCalendarAdded.Calendars.Count == 0) _calendarGroups.Remove(groupWithCalendarAdded); } CalendarGroup calGroup; if (_calendarGroups.Count > 0) { int index = 0; calGroup = _calendarGroups[index]; calGroup.Calendars.Add(calendar); } else { calGroup = new CalendarGroup(); calGroup.Calendars.Add(calendar); _calendarGroups.Add(calGroup); } }
Any questions just drop a message here, apologies for the delay I was on leave.
Anne