public ItemsViewModel() : base() { Title = "Browse"; Items = new ObservableCollection <Resres>(); LoadItemsCommand = new Command(async() => await ExecuteLoadItemsCommand()); MessagingCenter.Subscribe <NewItemPage, Resres>(this, "AddItem", async(obj, item) => { var newItem = item as Resres; Items.Add(newItem); await ResresStore.AddItemAsync(newItem); }); }
async Task ExecuteLoadItemsCommand() { if (IsBusy) { return; } IsBusy = true; try { Items.Clear(); var items = await ResresStore.GetItemsAsync(true); if (null != items) { foreach (var item in items) { Items.Add(item); } Debug.WriteLine($"ResresStore: {Items.Count} resources found"); } else { Debug.WriteLine("ResresStore: No items found."); } } catch (Exception ex) { Debug.WriteLine(ex); } finally { IsBusy = false; } }