0

我正在使用此示例代码来获取日历约会。我想将项目转换为字符串:例如在消息框中显示第一项。解决办法是什么??

private void SearchAppointments_Click(object sender, RoutedEventArgs e)
    {
        Appointments appts = new Appointments();
        appts.SearchCompleted += new EventHandler<AppointmentsSearchEventArgs>(Appointments_SearchCompleted);
        appts.SearchAsync(DateTime.Now, DateTime.Now.AddDays(1), 2,null);
    }


    void Appointments_SearchCompleted(object sender, AppointmentsSearchEventArgs e)
    {
        try
        {
            //Bind the results to the list box that displays them in the UI.
            AppointmentResultsData.DataContext = e.Results;
        }
        catch (System.Exception)
        {
            //That's okay, no results.
        }
    }
4

1 回答 1

0

结果是 IEnumerable ,您可以这样做,例如:

  void Appointments_SearchCompleted(object sender, AppointmentsSearchEventArgs e)
  {
     try
     {
        AppointmentResultsData.DataContext = e.Results;
        MessageBox.Show(e.Results.ElementAt<Appointment>(0).Subject.ToString());
     }
     catch (System.Exception) { }
  }

当然,您可以显示约会类的其他属性,而不是主题。

于 2013-11-13T10:15:15.937 回答