Problem to fill a list when OnAppearing is invoked. RRS feed

  • Question

  • User73815 posted

    I'm doing an app that makes entries. So, I have a screen with a custom list, i say custom because it's a StackLayout inside a ScrollView, like cards. The rows comes as the "ItemSource" grows.

    Below the table, I have a button which goes to a register screen, so there I can fill the fields. When it's finished I store the data on a ObservableCollection at the ViewModel and back to the list's screen.

    I use OnAppearing to fill the list if I have some data, cause if not the app will show an Image that indicate the view is empty.

    The problem is sometimes the OnAppearing is so fast and it's verify the ObservableCollection before the new entry is added. So the Collection isn't have any data.

    Look this:

     protected override void OnAppearing () {
        //Here's my ScrollView:
        if (((TestClassViewModel)BindingContext).Items.Any())
            foreach(var item in ((TestClassViewModel)BindingContext).Items)
                stack.Children.Add (item)
        //The same happens if I use a ListView:
        if (((TestClassViewModel)BindingContext).Items.Any())
            listItens.ItemSource = ((TestClassViewModel)BindingContext).Items //This is to "refresh"
        base.OnAppearing ();
    Monday, November 23, 2015 1:17 PM

All replies

  • User2148 posted

    Have you tide to use


    Monday, November 23, 2015 1:27 PM
  • User73815 posted

    It works with the StackLayout. But isn't work with ListView.

    Monday, November 23, 2015 3:46 PM
  • User2148 posted

    Roberto, if you post a working project that represent the problem we can help you to find a solution. Otherwise it's difficult...

    Monday, November 23, 2015 3:49 PM
  • User73815 posted

    Sorry, my mistake. I already solve the problem! It was an internal error.

    Monday, November 23, 2015 4:05 PM