示例#1
0
        public ShoppingListsViewModel()
        {
            Title            = "My Lists";
            Items            = new ObservableCollection <ShoppingList>();
            LoadItemsCommand = new Command(async() => await ExecuteLoadItemsCommand());

            MessagingCenter.Subscribe <NewShoppingListPage, ShoppingList>(this, "AddShoppingList", async(obj, item) =>
            {
                var newItem = item as ShoppingList;
                Items.Add(newItem);
                await DataStoreShoppingList.AddItemAsync(newItem);
            });
        }
示例#2
0
        async Task ExecuteLoadItemsCommand()
        {
            IsBusy = true;

            try
            {
                Items.Clear();
                var items = await DataStoreShoppingList.GetItemsAsync(true);

                foreach (var item in items)
                {
                    Items.Add(item);
                }
            }
            catch (Exception ex)
            {
                Debug.WriteLine(ex);
            }
            finally
            {
                IsBusy = false;
            }
        }