Quantcast
Channel: Xamarin.Forms — Xamarin Community Forums
Viewing all articles
Browse latest Browse all 91519

Problem to fill a list when OnAppearing is invoked.

$
0
0

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 ();

  }

Viewing all articles
Browse latest Browse all 91519

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>