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.
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
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.
Would you please post code snippet for event trigger? Thanks
Hello Anne,
You can easy determine it by handling ‘PreviewMouseUp’ event of the XamScheduleView like :
private void scheduleView_PreviewMouseUp(object sender, MouseButtonEventArgs e)
{
if (this.scheduleView.SelectedActivities.Count != 0 && this.scheduleView.SelectedActivities[0] is Appointment)
Appointment app = this.scheduleView.SelectedActivities[0] as Appointment;
}
Please in future create a separate thread for each of your questions.
Let me know, if you need any further assistance on this matter.
Is there a way to determine which appointment selected?