locked
ListView RRS feed

  • Question

  • I want a ListView to be created for displaying a collection of data in my UI.  I am calling the the function(ShowList), as shown below, from another class. And I have created the ListView in the xaml. However in the UI I dont see the list at all. 

    However if there is button in the UI and in the button's onCLick event I add the following code it works.

    But I want the ListView to be displayed as soon as the user comes to this UI class.

    Please help

    Here is the sample code:

    public sealed partial class someclass : UserControl {

    private void Showlist()

    {

    foreach(var somedata in data)

    {

    listview.Items.Add(somedata);

    }

    }

    }


    recieved alert


    • Edited by padaka Thursday, October 17, 2013 3:29 PM
    Thursday, October 17, 2013 3:28 PM

All replies

  • can you show us the xaml for this usercontrol? also how you are adding this UserControl to Page?

    Thanks, Sachin

    Thursday, October 17, 2013 3:38 PM
  • Very similar to the one mentioned in the msdn example:

    <ListViewx:Name="listView1" SelectionChanged="ListView_SelectionChanged">
    <x:String>Item 1</x:String>
    <x:String>Item 2</x:String>
    </ListView>                               

    But I did not get your question regarding adding it to usercontrol to page.


    recieved alert

    Thursday, October 17, 2013 5:31 PM
  • From this declaration in your first post - class someclass : UserControl, it seems ListView is inside user control. To display this user control we need to add this on Page class either in page xaml or at runtime.  How you are consuming this user control inside your page?  


    Thanks, Sachin

    Thursday, October 17, 2013 7:39 PM