SQLite Mvvm load async items in constructor

Hello,

why the nodes are printed in the console and dont show in the cell?

public class ProducttreeViewModel
    {
        ObservableCollection<Node> Nodes { get; set; }

        public ProducttreeViewModel()
        {
            Nodes = new ObservableCollection<Node>();
            ShowAllRows();
        }

        async void ShowAllRows()
        {
            var nodes = await App.Database.database.Table<Node>().ToListAsync();
            foreach (var node in nodes)
            {
                Nodes.Add(node);
                Debug.WriteLine(node.ToString());
            }
        }
    }

<ContentPage.Content>
        <ListView ItemsSource="{Binding Nodes}">
            <ListView.ItemTemplate>
                <DataTemplate>
                    <TextCell Text="{Binding Bild}" />
                </DataTemplate>
            </ListView.ItemTemplate>
        </ListView>
    </ContentPage.Content>

Maybe because its async and i have to fill the observablecollection in the ui thread?

Answers

Sign In or Register to comment.