Exemplo n.º 1
0
        /// <summary>
        /// Handler for event. It makes drag from the cell.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="args">Mouse event arguments.</param>
        public void HandleMouseLeftButtonDown(InventoryCellViewModel sender, MouseEventArgs args)
        {
            if (this.Item != null)
            {
                DependencyObject dragSource = args.Source as DependencyObject;

                DragDrop.DoDragDrop(dragSource, this, DragDropEffects.Move);
            }
        }
Exemplo n.º 2
0
 /// <summary>
 /// Handler for DragOver event. It describes conditions for dropping.
 /// </summary>
 /// <param name="sender">The source of the event.</param>
 /// <param name="args">Drag&Drop arguments.</param>
 public void HandleDragOver(InventoryCellViewModel sender, DragEventArgs args)
 {
     if (args.Data.GetDataPresent(typeof(ItemsSourceViewModel)))
     {
         args.Effects = DragDropEffects.Copy;
     }
     else
     {
         args.Effects = DragDropEffects.None;
     }
 }
Exemplo n.º 3
0
        /// <summary>
        /// Handler for Drop event.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="args">Drag&Drop arguments.</param>
        public void HandleDrop(Image sender, DragEventArgs args)
        {
            if (null != args.Data && args.Data.GetDataPresent(typeof(ItemsSourceViewModel)))
            {
                ItemsSourceViewModel data = (ItemsSourceViewModel)args.Data.GetData(typeof(ItemsSourceViewModel));

                _inventoryCell.Amount++;
                _inventoryCell.Item = _itemsRepository.GetItemById(data.Item.Id);
                //_inventoryCell.Item.ImageSource = data.Item.ImageSource;

                NotifyOfPropertyChange(() => Amount);
                NotifyOfPropertyChange(() => ImageSource);
            }
            else if (null != args.Data && args.Data.GetDataPresent(typeof(InventoryCellViewModel)))
            {
                InventoryCellViewModel data = (InventoryCellViewModel)args.Data.GetData(typeof(InventoryCellViewModel));

                if (data == this || data?.Item == null)
                {
                    return;
                }

                if (_inventoryCell.Amount == 0)
                {
                    _inventoryCell.Item = data.Item;
                    NotifyOfPropertyChange(() => ImageSource);
                }

                _inventoryCell.Amount += data.Amount;
                NotifyOfPropertyChange(() => Amount);

                data.ClearCell();
            }
            else
            {
                return;
            }

            _inventoryCellRepository.UpdateCell(_inventoryCell);
        }