1

So far I'm having trouble finding any similar question, so I'll ask here:

I have an item source (say, a list of 10 person) bound to a ListView. The list is populated asynchronously, and let's say, the list item would be added one item (person) at a second. Could you teach me how to make my ListView displays the item right from the first item instead of waiting for the tenth item then displays them all together?

Any working sample would be appreciated.

Thank you in advance.

XAML:

    <ListView ItemsSource="{Binding tempData, Mode=TwoWay}" Width="1000" Height="1000">
        <ListView.ItemTemplate>
            <DataTemplate>
                <Grid Width="100" Height="50">
                    <TextBlock Text="{Binding name}"/>
                </Grid>
            </DataTemplate>
        </ListView.ItemTemplate>
    </ListView>

CS (frankly I'm using cloud service, so the actual code is basically like:

await app.WorkWith().Data<Person>().GetAll().ExecuteAsync();

So, I take it that the line above would mean:

        private async Task<List<Person>> GenerateItem()
    {
        List<Person> tempData = new List<Person>(); 

        tempData.Add(new Person() { name = "name1"});
        await Task.Delay(1000);
        tempData.Add(new Person() { name = "name1" });
        await Task.Delay(1000);
        tempData.Add(new Person() { name = "name1" });
        await Task.Delay(1000);
        tempData.Add(new Person() { name = "name1" });
        await Task.Delay(1000);
        tempData.Add(new Person() { name = "name1" });
        await Task.Delay(1000);
        tempData.Add(new Person() { name = "name1" });
        await Task.Delay(1000);
        tempData.Add(new Person() { name = "name1" });
        await Task.Delay(1000);
        tempData.Add(new Person() { name = "name1" });
        await Task.Delay(1000);
        tempData.Add(new Person() { name = "name1" });
        await Task.Delay(1000);
        return tempData;
    }

And finally:

        private async void Populate()
    {

        List<Person> tempData = await GenerateItem();
        listView1.ItemsSource = tempData;            
    }
5
  • you want to show them getting listed gradually without any waiting? Commented Dec 3, 2013 at 6:40
  • I think that is not possible with a ListView purely because its a server control and once it is data bound fully only then server would send response.. Commented Dec 3, 2013 at 6:48
  • Yep, exactly. Just a few moment ago I stumble upon INotifyPropertyChanged. It might has something to do with asynchronous item update (display) on the ListView, I suppose. Commented Dec 3, 2013 at 6:50
  • What is your exact problem? Please post what you've done so far. Commented Dec 3, 2013 at 6:57
  • if you have a very large list to show may be you can also see this codeproject.com/Articles/37641/… Commented Dec 3, 2013 at 7:01

1 Answer 1

1

Just use ObservableCollection .... When item is added to collection then CollectionChanged are raised and your listview/gridview updated itself

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.