示例#1
0
        async Task ExecuteLoadCategoriesCommand()
        {
            if (IsBusy)
            {
                return;
            }

            IsBusy = true;

            try
            {
                Categories.Clear();
                var categories = await DataStoreCategory.GetItemsAsync(true);

                foreach (var category in categories)
                {
                    Categories.Add(category);
                }
            }
            catch (Exception ex)
            {
                Debug.WriteLine(ex);
            }
            finally
            {
                IsBusy = false;
            }
        }
示例#2
0
        public CategoriesViewModel()
        {
            Title                 = "КАТЕГОРИИ КНИГ";
            Categories            = new ObservableCollection <Category>();
            LoadCategoriesCommand = new Command(async() => await ExecuteLoadCategoriesCommand());

            MessagingCenter.Subscribe <NewCategoryPage, Category>(this, "AddItem", async(obj, category) =>
            {
                var newItem = category as Category;
                Categories.Add(newItem);
                await DataStoreCategory.AddItemAsync(newItem);
            }
                                                                  );
        }