locked
[UWP]how to add the selected item to listview RRS feed

  • Question

  • Hi,

     I am developing UWP application in that I am using the predefined class of ContactPicker when I am clicking the button its open the contacts window of people app here my main problem is occurs when I am select the any one of the contact I want to add that select contact to my listview in my app. 


    • Moved by Kristin Xie Monday, November 30, 2015 8:33 AM move to better forum
    • Edited by Xavier Xie-MSFT Tuesday, December 1, 2015 5:58 AM edit title
    Friday, November 27, 2015 6:47 AM

Answers

  • There is a downloadable code sample of how to use the ContactPicker class to select one or more contacts and how to display a list of contacts to the user available in the code gallery: https://code.msdn.microsoft.com/windowsapps/Contact-Picker-App-sample-fc6677a1/

    Here is another example: http://www.c-sharpcorner.com/UploadFile/7e39ca/creating-contact-picker-in-windows-store-apps/

    Once you have selected a contact, you could simply add it to the Items collection of the ListView or to your ObservableCollection<T> source collection:

    ContactPicker cp = new ContactPicker();
    var contacts =  await cp.PickMultipleContactsAsync();
    if (contacts != null && contacts.Count > 0)
    {
        listView1.Items.Add(contacts[0].Name);
    }

    Hope that helps.

    Please remember to close your threads by marking helpful posts as answer and then start a new thread if you have a new question. Please don't ask several questions in the same thread.

    Sunday, November 29, 2015 2:25 PM

All replies

  • Hi,

    Try ListView.Items.Add

    regards


    Full of ideas but don&#39;t know how. Coding for fun.

    Friday, November 27, 2015 5:21 PM
  • You're best asking UWP questions in the technology specific forum.

    That one is a bit odd because there's a tagging system for headers. Read the sticky.

    https://social.msdn.microsoft.com/Forums/windowsapps/en-US/home?forum=wpdevelop

    .

    I mainly do wpf ( as you could tell if you took a look at the links in my sig ) but I do some UWA as well and they are both XAML technologies.

    With XAML you want to be using MVVM rather than event and code behind.

    Or if you don't now, you will when you go for an interview. Almost every single teams uses MVVM.

    .

    Once you have a contact picked, you should add it to an observablecollection your ListView Itemssource is bound to.


    Hope that helps.

    Technet articles: WPF: MVVM Step 1; All my Technet Articles

    Friday, November 27, 2015 8:14 PM
  • There is a downloadable code sample of how to use the ContactPicker class to select one or more contacts and how to display a list of contacts to the user available in the code gallery: https://code.msdn.microsoft.com/windowsapps/Contact-Picker-App-sample-fc6677a1/

    Here is another example: http://www.c-sharpcorner.com/UploadFile/7e39ca/creating-contact-picker-in-windows-store-apps/

    Once you have selected a contact, you could simply add it to the Items collection of the ListView or to your ObservableCollection<T> source collection:

    ContactPicker cp = new ContactPicker();
    var contacts =  await cp.PickMultipleContactsAsync();
    if (contacts != null && contacts.Count > 0)
    {
        listView1.Items.Add(contacts[0].Name);
    }

    Hope that helps.

    Please remember to close your threads by marking helpful posts as answer and then start a new thread if you have a new question. Please don't ask several questions in the same thread.

    Sunday, November 29, 2015 2:25 PM