You should move your data access code into the ViewModel, then in the setter of the Selected date you can call the GetAppointments method every time the date is changed. Something like this
private DateTime _selectedDate;
public DateTime SelectedDate
{
get { return _selectedDate; }
set
{
if (_selectedDate != value)
{
_selectedDate = value;
GetAppointments(_selectedDate);
NotifyPropertyChanged("SelectedDate");
}
}
}
public ObservableCollection<SCSMAppointment> Appointments { get; private set; }
public AppointmentOverviewViewModel()
{
Appointments = new ObservableCollection<SCSMAppointment>();
SelectedDate = DateTime.Today;
}
private void GetAppointments(datetime selectedDate)
{
Appointments.Clear();
DateTime firstDay = new DateTime(DateTime.Now.Year, DateTime.Now.Month, 1);
int countDays = DateTime.DaysInMonth(DateTime.Now.Year, DateTime.Now.Month);
CalendarFolder calendar = CalendarFolder.Bind(service, WellKnownFolderName.Calendar, ps);
CalendarView cView = new CalendarView(firstDay, firstDay.AddDays(countDays));
FindItemsResults<Appointment> appointments = calendar.FindAppointments(cView);
foreach (Appointment a in appointments)
{
Appointments.Add(scsmapp);
}
}
Then you can remove all of the data access code from your App's OnStartup event.