public ItemsViewModel()
        {
            Title            = "Browse";
            Items            = new ObservableCollection <Item>();
            LoadItemsCommand = new Command(async() => await ExecuteLoadItemsCommand());

            MessagingCenter.Subscribe <NewItemPage, Item>(this, "AddItem", async(obj, item) =>
            {
                var newItem = item as Item;
                Items.Add(newItem);
                await DataStore.AddItemAsync(newItem);
            });

            MessagingCenter.Subscribe <AddCategory, string>(this, "AddCategory", async(obj, category) =>
            {
                await DataStore.AddCategoryAsync(category);
            });
        }
示例#2
0
        public CategoriesViewModel()
        {
            Title                 = "Categories";
            Categories            = new ObservableCollection <Category>();
            LoadCategoriesCommand = new Command(async() => await ExecuteLoadCategoriesCommand());

            MessagingCenter.Subscribe <NewCategoryPage, Category>(this, "AddCategory", async(obj, category) =>
            {
                var _category = category as Category;
                Categories.Add(_category);
                await DataStore.AddCategoryAsync(_category);
            });

            MessagingCenter.Subscribe <ItemsPage, Category>(this, "DeleteCategory", async(obj, category) =>
            {
                var _category = category as Category;
                Categories.Remove(_category);
                await DataStore.DeleteCategoryAsync(_category);
            });
        }