コード例 #1
0
ファイル: MainViewModel.cs プロジェクト: korzonkiee/store
 public void AddProduct(Product product)
 {
     Task.Run(async() =>
     {
         await productsService.AddProductToDatabase(product);
         var products = await productsService.GetProducts();
         Products     = new ObservableRangeCollection <Product>(products);
         //DispatcherHelper.CheckBeginInvokeOnUI(() =>
         //{
         //    Products = new ObservableRangeCollection<Product>(products);
         //});
     });
 }
コード例 #2
0
        public async Task AddProduct(Product product)
        {
            try
            {
                await productsService.AddProductToDatabase(product);
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }

            var products = await productsService.GetProducts();

            Products = new ObservableCollection <Product>(products);
            await CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
            {
                Products = new ObservableCollection <Product>(products);
            });
        }