【问题标题】:How to fill a LongListSelector with the results of a search in the Contacts.如何用联系人中的搜索结果填充 LongListSelector。
【发布时间】:2014-02-06 21:54:22
【问题描述】:

我只是编程的初学者,我正在尝试在我的应用程序中制作一个 Windows Phone 应用程序,我希望能够选择联系人。我首先把它放在一个列表框中,它工作得很好,但我想让它变得更好,所以我想把它放到一个 Longlistselector 中。这就是问题发生的地方。 这是我得到的错误:“System.Collections.Generic.List”不包含“SearchCompleted”的定义,并且没有可以找到接受“System.Collections.Generic.List”类型的第一个参数的扩展方法“SearchCompleted” (您是否缺少 using 指令或程序集引用

我不,它不是大会,但那是我迷路的地方。我在 xaml 中有很长的 listlongselector,但这是我一直迷路的地方。

namespace contacts
{
public partial class MainPage : PhoneApplicationPage
{
    int TapCount = 0;

    List<Contacts> contacts = new List<Contacts>();

    // Constructor
    public MainPage()
    {
        InitializeComponent();
        contacts.SearchCompleted += new EventHandler<ContactsSearchEventArgs>(contacts_SearchCompleted);
        SearchContacts(String.Empty); 

    }

    private async void SayWords(string words)
    {
        SpeechSynthesizer synth = new SpeechSynthesizer();

        await synth.SpeakTextAsync(words);


    }




    void contacts_SearchCompleted(object sender, ContactsSearchEventArgs e)
    {
        ContactList.ItemsSource = contacts;
    }

    private void SearchContacts(string searchterm)
    {
        contacts.SearchAsync(searchterm, FilterKind.DisplayName, null);
    }  


    }
}

【问题讨论】:

    标签: c# windows-phone-8 contacts longlistselector


    【解决方案1】:

    您不应创建 ListContacts。 AList 没有SearchCompleted 事件。 Contacts 类可以。接下来,您的LongListSelecterItemSource 应在事件处理程序中设置为e.Results

    namespace contacts
    {
        public partial class MainPage : PhoneApplicationPage
        {
            int TapCount = 0;
    
            var contacts = new Contacts();
    
            // Constructor
            public MainPage()
            {
                InitializeComponent();
                contacts.SearchCompleted += new EventHandler<ContactsSearchEventArgs>(contacts_SearchCompleted);
                SearchContacts(String.Empty); 
            }
    
            void contacts_SearchCompleted(object sender, ContactsSearchEventArgs e)
            {
                ContactList.ItemsSource = e.Results;
            }
    
            private void SearchContacts(string searchterm)
            {
                contacts.SearchAsync(searchterm, FilterKind.DisplayName, null);
            }
        }
    }
    

    希望这会有所帮助。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2013-11-30
      • 1970-01-01
      • 1970-01-01
      • 2014-02-14
      • 1970-01-01
      • 2015-02-25
      • 1970-01-01
      相关资源
      最近更新 更多