Ejemplo n.º 1
0
        void notifications_DeleteProduct(object sender, DbProductDeleteEventArgs e)
        {
            DbProductTreeViewItem productTreeViewItem = e.DbProductTreeViewItem;

            //To get the parent of the productTreeViewItem which is a CategoryTreeViewItem
            DbCategoryTreeViewItem Parent = productTreeViewItem.Parent as DbCategoryTreeViewItem;

            //Removing the TreeItem from Parent
            Parent.Items.Remove(productTreeViewItem);
        }
        void deleteProduct_Click(object sender, RoutedEventArgs e)
        {
            var deleteCtxMenuItem = e.Source as DeleteCtxMenuItem;
            var product           = deleteCtxMenuItem.Tag as Product;

            //To get the Tree from which the context menu is called
            DbProductTreeViewItem dbProductTreeViewItem = ((ContextMenu)deleteCtxMenuItem.Parent).PlacementTarget as DbProductTreeViewItem;

            _dbTreeViewNotifications.OnDbDeleteProduct(new DbProductDeleteEventArgs()
            {
                DbProductTreeViewItem = dbProductTreeViewItem
            });
        }
Ejemplo n.º 3
0
        private async Task AddProductsUnderCategory(DbCategoryTreeViewItem item, Category category)
        {
            var synchronizationContext = TaskScheduler.FromCurrentSynchronizationContext();
            var cancellationToken      = new CancellationToken();

            await Task.Factory.StartNew(() =>
            {
                item.Items.Clear();
                foreach (var product in category.Products)
                {
                    var treeViewItem = new DbProductTreeViewItem(product, false);
                    treeViewItem.Tag = product;
                    item.Items.Add(treeViewItem);
                }
            }, cancellationToken, TaskCreationOptions.None, synchronizationContext);
        }