Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
330
XamOutlookCalendarView selected activities
posted

Hi,

How can I manipulate which item (appointment) is selected in the XamOutlookCalendarView?
I found that the SelectedActivities property contains the selected items' data but modifying this collection (add or remove elements) does not do any modification on which item is displayed as selected.
I have to implement a search functionality which selects the first matching appointment and moves into view, but I did find how can I do that. 

Thanks,
Istvan

Parents
No Data
Reply
  • 54937
    Suggested Answer
    Offline posted

    The SelectedActivities of the xamOutlookCalendarView is synchronized with the SelectedActivities of the ScheduleControlBase within for the current view (i.e. the DayView, MonthView or ScheduleView). I verified that clearing the collection or removing an item does affect the display. Adding an item to the selection is a bit more complicated because you have to get the Activity from the XamScheduleDataManager which depending on the DataConnector you are using (and its underlying storage) could be synchronous or asynchronous. Here's a simplified example. Note there is currently no public method for bringing an activity into view so you may want to submit a suggestion for adding that.

      private void OnSearchClick(object sender, RoutedEventArgs e)
      {
       string text = this.searchText.Text;
       var data = (ScheduleData)this.DataContext;
       var dataManager = this.view.DataManager;
       var tzProvider = dataManager.DataConnector.TimeZoneInfoProviderResolved;

       if (string.IsNullOrEmpty(text))
        return;

       // this is just a simple search to find the first. you'd probably want to
       // make you're own routine that continues/starts from the selected activity
       // and then wraps around as needed or possibly that just searches within a
       // given range
       foreach (var dataItem in data.Appointments)
       {
        string subject = dataItem.Subject;

        if (subject != null && subject.IndexOf(text, StringComparison.CurrentCultureIgnoreCase) >= 0)
        {
         Resource resource = dataManager.ResourceItems.GetResourceFromId(dataItem.OwningResourceId);
         ResourceCalendar calendar = resource.Calendars.FirstOrDefault((c) => c.Id == dataItem.OwningCalendarId);

         Debug.Assert(calendar != null);

         if (calendar != null)
         {
          ActivityQuery query = new ActivityQuery(ActivityTypes.Appointment, new DateRange(dataItem.Start, dataItem.End), calendar);
          var result = dataManager.GetActivities(query);

          if (result.IsComplete)
          {
           var activity = result.Activities.FirstOrDefault((a) => a.DataItem == dataItem);

           if (activity != null)
           {
            this.view.SelectedActivities.Clear();
            this.view.SelectedActivities.Add(activity);

            // currently there is no public method for bring an activity into view
            // but editing an activity will bring it into view. we can just
            // temporarily prevent editing
            if (dataManager.Settings == null)
             dataManager.Settings = new ScheduleSettings();

            if (dataManager.Settings.AppointmentSettings == null)
             dataManager.Settings.AppointmentSettings = new AppointmentSettings();

            var apptSettings = dataManager.Settings.AppointmentSettings;

            var cmd = new ScheduleControlBaseCommand(ScheduleControlCommand.EditSelectedActivity);
            var oldValue = apptSettings.AllowEdit;
            apptSettings.AllowEdit = false;
            cmd.Execute(this.view);
            apptSettings.AllowEdit = oldValue;
           }
          }
          else
          {
           // otherwise you have to hold the result, listen to the property change
           // for when the IsComplete is true and then access the activies and
           // manipulate the selected activities
           Debug.Assert(false, "Need to handle this");
          }
          break;
         }
        }
       }
      }

Children