C# 如何在WindowsPhone7中将listbox数据上下文转换为字符串

C# 如何在WindowsPhone7中将listbox数据上下文转换为字符串,c#,windows-phone-7,listbox,tostring,C#,Windows Phone 7,Listbox,Tostring,我正在使用此示例代码获取日历约会。 我想将项目转换为字符串:例如,显示消息框中的第一个项目。 解决办法是什么 private void SearchAppointments_Click(object sender, RoutedEventArgs e) { Appointments appts = new Appointments(); appts.SearchCompleted += new EventHandler<AppointmentsSea

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

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.
        }
    }
private void searchappointment\u单击(对象发送者,路由目标)
{
预约appts=新预约();
appts.SearchCompleted+=新事件处理程序(约会\u SearchCompleted);
appts.SearchAsync(DateTime.Now,DateTime.Now.AddDays(1),2,null);
}
作废约会\u搜索已完成(对象发件人、约会搜索目标e)
{
尝试
{
//将结果绑定到在UI中显示结果的列表框。
AppointmentResultsData.DataContext=e.Results;
}
捕获(系统异常)
{
//没关系,没有结果。
}
}

结果是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) { }
  }
void appointment\u search已完成(对象发送者,appointssearcheventargs e)
{
尝试
{
AppointmentResultsData.DataContext=e.Results;
Show(e.Results.ElementAt(0.Subject.ToString());
}
catch(System.Exception){}
}

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

那么您想将项目放在一个大字符串中吗?还是一个字符串中的每个项目?一个字符串中的每个项目string@user2987059如果它解决了你的问题,别忘了接受它作为答案:)