SearchCompleted 事件

2012/2/9

当搜索约会完成时发生。

Namespace:  Microsoft.Phone.UserData
程序集:  Microsoft.Phone(位于 Microsoft.Phone.dll 中)
XMLNS for XAML:未映射到 xmlns。

public event EventHandler<AppointmentsSearchEventArgs> SearchCompleted
<object SearchCompleted="EventHandler<AppointmentsSearchEventArgs>" .../>

若要将该事件与处理该事件的方法关联,请创建一个委托想向该事件中添加该委托的一个实例。除非您移除委托,否则只要该事件发生,便会调用事件处理程序。

有关处理事件的更多信息,请参阅使用事件

以下示例假定您拥有一个 Windows Phone 应用程序,该应用程序包含一个带有名为 SearchAppointments 的按钮的页面。代码假定您拥有一个名为 AppointmentResultsData 的数据绑定列表框。在此示例中,您搜索在接下来的 7 天中的所有约会。有关完整示例(包括 XAML),请参阅如何:访问 Windows Phone 的日历数据

using System;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Input;
using Microsoft.Phone.Controls;
using Microsoft.Phone.UserData;

namespace ContactsAndCalendarTestApp
{
    public partial class AppointmentsPage : PhoneApplicationPage
    {
        public AppointmentsPage()
        {
            InitializeComponent();
        }


        private void SearchAppointments_Click(object sender, RoutedEventArgs e)
        {
            AppointmentResultsData.DataContext = null;
            Appointments appts = new Appointments();

            appts.SearchCompleted += new EventHandler<AppointmentsSearchEventArgs>(Appointments_SearchCompleted);

            DateTime start = new DateTime();
            start = DateTime.Now;
            //MessageBox.Show(start.ToLongDateString());

            DateTime end = new DateTime();
            end = start.AddDays(7);
            //MessageBox.Show(end.ToLongDateString());

            appts.SearchAsync(start, end, 20, "Appointments Test #1");
        }


        void Appointments_SearchCompleted(object sender, AppointmentsSearchEventArgs e)
        {
            //MessageBox.Show(e.State.ToString());
            //MessageBox.Show(e.StartTimeInclusive.ToShortDateString());
            //MessageBox.Show(e.EndTimeInclusive.ToShortDateString());
        
            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.
            }
        }
    }
}

Windows Phone OS

在 7.1 中支持

Windows Phone

显示: